SQL reference (MySQL and MariaDB dialects)

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#

SQL
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_name

Arguments#

NameMeaningDefault
SESSION / LOCALThe setting is this connection's.the scope when none is written
GLOBALThe 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
DEFAULTBack to the server's value (the value set with SET GLOBAL, or the default).none
word valueSET x = ON, SET sql_mode = ANSI and similar bare words are read as text.none

Remarks#

  • A switch is 1 or 0 in SELECT @@switch and ON or OFF in SHOW 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 GLOBAL of 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 DB for MySQL, 11.4.13-MariaDB-Raft DB for MariaDB), the character_set_* family and collation_* (all utf8mb4), transaction_isolation / tx_isolation (READ-COMMITTED, see transactions), lower_case_table_names 0, time_zone SYSTEM, system_time_zone UTC, log_bin OFF, gtid_mode OFF, event_scheduler OFF, performance_schema OFF, have_ssl DISABLED, port 3306.
  • Default sql_mode: MySQL ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION; MariaDB STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION.
  • SET NAMES and SET CHARACTER SET are accepted; the connection stays utf8mb4.
  • SHOW STATUS is not a list of server counters: it has three fixed rows.

Not supported yet#

  • SET PERSIST and SET PERSIST_ONLY (error 1235).
  • SET ROLE and SET DEFAULT ROLE (roles do not exist; syntax error).

Examples#

Example:

SQL
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;

See also#