System variables
How system variables are listed, read and set in the MySQL and MariaDB front-ends, and which ones change behaviour.
A session starts with every system variable of the server of its dialect with that server's default value: 513 variables of MySQL 9.7 and 554 of MariaDB 11.4, without the machine-specific ones (D81, generated from MySQL and MariaDB servers). The front-end then overrides the few values that it does differently.
Syntax#
SET [GLOBAL | SESSION | LOCAL] var_name { = | := } { expr | DEFAULT | word }
[, [GLOBAL | SESSION | LOCAL] var_name = value] ...
SET @@[global. | session.]var_name = value
SET @user_var = expr
SET NAMES charset_name [COLLATE collation_name]
SET CHARACTER SET charset_name
SET [GLOBAL | SESSION] TRANSACTION characteristic [, ...]
SHOW [GLOBAL | SESSION] VARIABLES [LIKE 'pattern']
SELECT @@var_name, @@global.var_name, @@session.var_nameArguments#
| Name | Meaning | Default |
|---|---|---|
SESSION / LOCAL | The setting is this connection's. | the scope when none is written |
GLOBAL | The setting is kept for the whole front-end and seen by new sessions (@@global.x, SHOW GLOBAL VARIABLES). Needs SUPER for accounts other than the configuration's administrator (error 1227). | none |
DEFAULT | Back to the server's value (the value set with SET GLOBAL, or the default). | none |
| word value | SET x = ON, SET sql_mode = ANSI and similar bare words are read as text. | none |
Remarks#
- A switch is 1 or 0 in
SELECT @@switchandONorOFFinSHOW VARIABLES. - An unknown variable is error 1193, except these nine that drivers set blindly and that are kept without effect:
net_write_timeout,net_read_timeout,sql_big_selects,max_execution_time,lc_messages,lc_time_names,session_track_schema,wait_timeout,interactive_timeout.SET GLOBALof any name is accepted for an account that may set it. - Variables that change behaviour (found in the code):
sql_mode(strict conversion,ONLY_FULL_GROUP_BY, no-zero dates; the list is normalised the way the server keeps it),autocommit,foreign_key_checks,div_precision_increment,group_concat_max_len,max_sp_recursion_depth. All others are kept and shown but do nothing here. - Values this front-end sets itself:
version(8.0.36-Raft DBfor MySQL,11.4.13-MariaDB-Raft DBfor MariaDB), thecharacter_set_*family andcollation_*(allutf8mb4),transaction_isolation/tx_isolation(READ-COMMITTED, see transactions),lower_case_table_names0,time_zoneSYSTEM,system_time_zoneUTC,log_binOFF,gtid_modeOFF,event_schedulerOFF,performance_schemaOFF,have_sslDISABLED,port3306. - Default
sql_mode: MySQLONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION; MariaDBSTRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION. SET NAMESandSET CHARACTER SETare accepted; the connection staysutf8mb4.SHOW STATUSis not a list of server counters: it has three fixed rows.
Not supported yet#
SET PERSISTandSET PERSIST_ONLY(error 1235).SET ROLEandSET DEFAULT ROLE(roles do not exist; syntax error).
Examples#
Example:
SET SESSION sql_mode='';
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SELECT @@sql_mode;
SET autocommit = 0;
SELECT @@autocommit;
SET foreign_key_checks = 0;
SET GLOBAL group_concat_max_len = 4096;
SHOW VARIABLES LIKE 'character_set_server';
SELECT DATABASE(), @@version_comment, @@max_allowed_packet, @@lower_case_table_names;