"MySQL"-System Variables @20210227

Environment overview

MySQL 8.0

What are System Variables?

System variables , maintained by MySQL, are used to control MySQL behavior.

Some system variables are variables installed by components and plug-ins, and can only be used after plug-ins or components are installed. These variables have "component name prefix" (or "plug-in name prefix"), but they still belong to system variables.

The scope of system variables

Global and Conversation

System variables have two scopes: global , affecting the entire operation of the service; session , affecting the operation of the current client connection;

A given system variable can have a global value and a session value at the same time .

The relationship between the two

When the service starts, all global variables are initialized to default values ​​or values ​​configured in options.

When the client connects, use the global variable value to initialize the session variable value. Note that for some special variables, the session parameter value will not be initialized by the global parameter value, which will be explained in the document description

How to set system variables?

Each system variable has a default value.

At startup, it can be set through command line options ; or through the configuration file (my.cnf) ;

At runtime, most variables can be set by the SET statement, which does not require restarting or stopping the database.

Command line options

1) It is the same as the normal command line options.
2) Either horizontal line or underscore can be used: --general_log=ON , --general-log=ON
3) Units (K, M, G) can be used, both upper and lower case: --innodb-log-file-size=16M --max-allowed-packet=1G

Through the command line option --maximum- var_name = value form, you can limit the maximum value of the parameter that SET can set.

Configuration file (my.cnf)

1) Similar to the command line option, just remove the prefix:

[mysqld]
innodb_log_file_size=16M
max_allowed_packet=1G

Use the SET statement

Most variables can be modified using the SET statement:
1) Reference by name;
2) Prefix modifier (optional);
3) Only underscores can be used, not horizontal lines;

Use the SET statement

Set global variables (temporary)

SET GLOBAL max_connections = 1000;
SET @@GLOBAL.max_connections = 1000;

Set global variables (and persist to the mysqld-auto.cnf file)

SET PERSIST max_connections = 1000;
SET @@PERSIST.max_connections = 1000;

Set global variables (only persist to the mysqld-auto.cnf file)

SET PERSIST_ONLY max_connections = 1000;
SET @@PERSIST_ONLY.max_connections = 1000;

Set session variables

SET SESSION sql_mode = 'TRADITIONAL';
SET @@SESSION.sql_mode = 'TRADITIONAL';
SET @@sql_mode = 'TRADITIONAL';

Precautions

After modifying the global variable, the new value will be used for the new connection; for the existing connection, modifying the value of the global variable will not affect the corresponding session variable (even if only the SET GLOBAL statement is used in the current connection , it will not affect the corresponding Session variables).

After the service is restarted, global variables will become invalid. If you want to persist, you should write the configuration file.

View system variables

Use SHOW VARIABLES LIKE'var_mame'; or SHOW VARIABLES statement to view system variables.

Note:
1) It is recommended to use underscores, because variables are all underscores stored in the database.

Required for permissions

Section 5.1.9.1, “System Variable Privileges”

references

Variables in MySQL: system variables (including: session variables, global variables), session variables (including: local variables, session variables)
How to change MySQL system parameters/variables
MySQL 5.7 Reference Manual/13.7.4.1 SET Syntax for Variable Assignment

Guess you like

Origin blog.csdn.net/u013670453/article/details/114164912