The content of this article:
- System variables
- User variables
Starting Date: 2018-04-18
System variables:
- System variables are variables that the system has already defined in advance.
- system variables generally have their special meanings. For example, some variables represent character sets, some variables represent certain MySQL file locations
- System variables include session-level variables (variables that are in effect when a session is connected, such as names), and global variables (variables that are in effect) "The global variables and session variables in the system variables are actually using a set of variables, but the conversation variables are only used when the session takes effect." 】
- Assignment of Session variables: Set variable name = value; "such as common set names =" UTF8 ";" or set @@ 变量 name = value
- Assignment of global variables: SET global variable name = value;
To view system variables:
Calls to System variables:
User variables:
- A user variable is a user-defined variable.
- To differentiate system variables from custom variables, the system specifies that user-defined variables must use an @ symbol
- How variables are defined:
set @变量名=1
- SELECT @ Variable Name: = value;
- Select value into @ variable name;
- The user variable can be used without declaring the definition, but the default is a null value
- User variables are session-level variables that take effect only in the secondary connection.
Local variables:
- Because local variables are user-defined, you can think of local variables as user variables "but different, not in the local use @"
- Local variables are commonly used in SQL statement blocks, such as stored procedure blocks, trigger blocks, and so on
- How to define a local variable:
- Use declare to declare a local variable, where the option default can be followed by a value that is paid to the variable: " a very important step, or it will be set to a user variable"
- Example: declare MYQ int;
- Example: declare myq int default 666;
- Set the value of the variable:
- Set variable name = value;
- Gets the value of the variable:
Create procedureMySet ()begin DeclareMyaint; DeclareMyqint default 777; SelectMya,myq; SetMyq=6; SetMya=666; SelectMya,myq;End; call MySet ();
Add:
- Some people may find the direct set variable name = value, or you can define a "user variable"; but this is a bad behavior "This behavior ignores the function of the respective variable", because you do not know whether it will conflict with the system variables, so the best user variable plus @
- because =, there are many places to judge whether equal, in order to avoid ambiguity, you can also use: = To assign a value
- "The above gives some other assignment methods, but it seems that some are not universal, such as: = only for user variables, so use caution ."
The MySQL variable