Variable
System variables and custom variables
System variables
System variables: System-defined variables, most of the system variables, generally do not require user control, system variables used to control the performance of the server such as: Autocommit, auto_increment and so on.
viewing system Variables
Show variables;
View variable values for a specific variable: any content that has data returned is a select view
View basic syntax for system variables: select @@ 变量 name;
Eg:select @ @version, @ @autocommit, @ @auto_increment_offset, @ @character_set_results;
modifying system Variables
There are two ways to modify system variables: Session level and global level
Set @@ 变量 name = value;
Set variable name = value;
Session level: Temporary modification, the current client is valid, when the secondary connection is valid.
Global level: One modification, permanent (valid for all clients)
Set global variable name = value;
Other clients need to restart the client to take effect.
Custom variables
In order to differentiate system variables, the system specifies that the custom variable must use an @ symbol.
SET @ variable name = value;
Select variable name;
In MySQL, "=" would implicitly consider the comparison of symbolic processing, and MySQL redefined a new assignment symbol for the concept of distinguishing between comparison and assignment---- : =
MYSQL allows you to get data from a data table and assign it to a variable : two ways
Scenario 1: Edge assignment, side view results
SELECT @ Variable Name: = Field name form data source; --Assigns a field from the database table to the variable.
Scenario 2: Only the assignment does not look at the result, it is strict: only one data record can be obtained, MySQL does not support data.
Select field List from table name into variable list;
The custom variables used are session-level. Variables are not database-sensitive and belong to the user level.
(16) The variables in MySQL