SQL reference (MySQL and MariaDB dialects)

SET statement

SET for system variables, user variables, character sets, passwords and transaction characteristics.

SET assigns system variables, user variables, the connection's character set and account passwords.

Syntax#

SQL
SET assignment [, assignment] ...

assignment:
    [GLOBAL | SESSION | LOCAL] var_name { = | := } value
  | @@[global. | session.]var_name = value
  | @user_var { = | := } expr
  | NAMES charset_name [COLLATE collation_name]

SET NAMES charset_name [COLLATE collation_name]
SET CHARACTER SET charset_name
SET PASSWORD [FOR account] = { 'plain' | PASSWORD('plain') }
SET [GLOBAL | SESSION] TRANSACTION characteristic [, ...]

value:
    expr | DEFAULT | bare_word

Arguments#

NameMeaningDefault
GLOBALFront-end wide; needs SUPER (error 1227).
SESSION, LOCALThis connection.the default scope
bare_wordA word as value (ON, OFF, ANSI) is read as text unless it is NULL, TRUE, FALSE or DEFAULT.
PASSWORD FOR accountSets another account's password; needs CREATE USER (or the mysql database privilege).the current account

Remarks#

  • System variables: see system variables. An unknown name is error 1193.
  • SET NAMES x and SET CHARACTER SET x are accepted for any character set name; the connection stays utf8mb4. A NAMES item may also stand in a list (SET a = 1, NAMES utf8mb4, which MariaDB Connector/J sends).
  • User variables take any expression; they are kept for the session. A user variable that was never set is NULL.
  • SET autocommit changes the transaction mode; see transactions.
  • SET TRANSACTION ... is read and ignored (there is one level, read uncommitted).
  • SET PASSWORD accepts the old PASSWORD('x') form.

Not supported yet#

  • SET PERSIST and SET PERSIST_ONLY (error 1235).
  • SET ROLE, SET DEFAULT ROLE, SET RESOURCE GROUP, SET STATEMENT var=value FOR ... (MariaDB): syntax error (1064).

Examples#

Example:

SQL
SET @a = 1, @b = 'one', @c = 10;
SET NAMES utf8mb4;
SET SQL_SAFE_UPDATES=0;
SET autocommit = 0;
SET SESSION sql_mode='';
SET GLOBAL group_concat_max_len = 4096;
SET PASSWORD = 'new secret';

See also#