mysql global and local variables

Global and local variables

When the server starts, will each global variable initialization (You can change these defaults through the command line or options file specified option) to their default values. Then, the server also maintains a set of session variables for each client connection, the current value of the client's session variables corresponding global variable is initialized at the time of connection.

As an example, when the server starts initializes called default_storage_engine, GLOBAL scope of system variables. After whenever a client connects to the server, the server for the client will be assigned individually named default_storage_engine, SESSION scope of system variables, the scope of the system according to the current value of the variable SESSION scope of the GLOBAL of the same name system variable is initialized.

Obviously, the scope of the system variables are set by GLOBAL boot option, which is valid for all clients, because when the system starts has not yet come of it client program to connect. Knowing the GLOBAL and SESSION scope of system variables, let's look at the syntax by the client to set the system variables during the server program is running:

SET [GLOBAL|SESSION] 系统变量名 = 值;

Or written like this will do:

SET [@@(GLOBAL|SESSION).]var_name = XXX;

For example, we want the scope of default_storage_engine GLOBAL system variable values ​​modified while the server is running for MyISAM, which is then wanted a new connection to the server clients are used as the default MyISAM storage engine, then we can choose the following two any statement in a be set:

语句一:SET GLOBAL default_storage_engine = MyISAM;
语句二:SET @@GLOBAL.default_storage_engine = MyISAM;

If you want the entry into force of the client, you can choose any one of the following three statements to set:

语句一:SET SESSION default_storage_engine = MyISAM;
语句二:SET @@SESSION.default_storage_engine = MyISAM;
语句三:SET default_storage_engine = MyISAM;

Three may be seen from the top of the sentence, if provided is omitted in the system variable scope statement, it is the default scope SESSION. That system variable name = value SET and SET SESSION system variable name = value equivalent.

View different scope of system variables
Since the system has a variable range of action points, SHOW VARIABLES statement that our view of what is a system variable scope of it?

答:默认查看的是SESSION作用范围的系统变量。

Of course, we can also add system variables which you want to view on the scope of the viewing system variables statement, like this:

SHOW [GLOBAL|SESSION] VARIABLES [LIKE 匹配的模式];

Guess you like

Origin www.cnblogs.com/zhxiansheng/p/11792942.html