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#
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_wordArguments#
| Name | Meaning | Default |
|---|---|---|
GLOBAL | Front-end wide; needs SUPER (error 1227). | |
SESSION, LOCAL | This connection. | the default scope |
bare_word | A word as value (ON, OFF, ANSI) is read as text unless it is NULL, TRUE, FALSE or DEFAULT. | |
PASSWORD FOR account | Sets 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 xandSET CHARACTER SET xare accepted for any character set name; the connection staysutf8mb4. ANAMESitem 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 autocommitchanges the transaction mode; see transactions.SET TRANSACTION ...is read and ignored (there is one level, read uncommitted).SET PASSWORDaccepts the oldPASSWORD('x')form.
Not supported yet#
SET PERSISTandSET PERSIST_ONLY(error 1235).SET ROLE,SET DEFAULT ROLE,SET RESOURCE GROUP,SET STATEMENT var=value FOR ...(MariaDB): syntax error (1064).
Examples#
Example:
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';