I. Global variables
Changes its parameters dynamically during system operation and fails after a reboot.
SET gloabl var=xxx;
SET @ @global. var=xxx; (set @ @var =xxx)
These two methods are equivalent
View the global variables of the system
Show global variables [like "%"];
Two. User variables
Valid for the current reply, the variable is destroyed after the reply is completed
SET @var =xxx;
SELECT @var: =uid from table where id=10;
With @ as the prefix identifier, set can use = or =: assignment, select can only be assigned by: =
Three. Session variables
Valid for the current reply, the variable is destroyed after the reply is completed
Set session Var_name = value;
SET @ @session. Var_name = value;
Set var_name = value;
The above three methods are equivalent
The difference between a session variable and a user variable is that, in addition to the prefix identifier, the session variable is a predefined set of variables, and you cannot define a user variable that does not exist.
Such as
Set test= ' test ';
[ERR] 1193-unknown system variable ' test ';
View variables for the current session
Show [session] variables [like "%"];(where session is the default and can not be written)
Common like eliminate MySQL default sql_mode mode, change to the most relaxed mode
Set sql_mode= ";
Four. Local variables
declear var INTEGER DEFAULT 0;
Generally defined between the begin and end statement blocks, the end of the statement block disappears.
Ps:
Between Begin and end is used to define a set of SQL compound statements;
Four types of variables for MySQL