MySQL Query Variables
In MySQL, we can use some variables to set and operate queries. These variables can affect the return of query results and the performance of the query. This article will introduce some commonly used MySQL query variables and how to use them.
@@global.variable_name is used to obtain the global variable value. You can obtain the MySQL global variable value by querying this variable.
For example, we can use the following command to query the maximum number of connections in MySQL:
SELECT @@global.max_connections;
@@session.variable_name is used to obtain the variable value of the current session. This value is only valid within the current session.
For example, we can use the following command to set the character set of the current session to utf8:
SET @@session.character_set_client = utf8;
@@local.variable_name is used to obtain the local variable value, which is only valid within the current session and cannot be used by other sessions.
For example, we can use the following command to set the local variable value to the current time:
SET @@local.time_zone = NOW();
SET variable_name = value is used to set the global variable value of MySQL, which affects the entire MySQL instance, not just the current session. This method is more direct and easier to understand than the @@global.variable_name method.
For example, we can use the following command to set the maximum number of connections to 1000:
SET max_connections = 1000;
SET SESSION variable_name = value is used to set the variable value of the current session. This value only takes effect within the current session.
For example, we can use the following command to set the transaction isolation level of the current session to READ COMMITTED:
SET SESSION tx_isolation = 'READ-COMMITTED';
SET LOCAL variable_name = value is used to set the local variable value. This value only takes effect within the current session and cannot be used by other sessions.
For example, we can use the following command to set the local variable value to the current time:
SET LOCAL time_zone = NOW();
SHOW GLOBAL VARIABLES is used to display the value of MySQL global variables.
For example, we can use the following command to display the character set of MySQL:
SHOW GLOBAL VARIABLES LIKE 'character_set%';
SHOW SESSION VARIABLES is used to display the variable values of the current session.
For example, we can use the following command to display the character set of the current session:
SHOW SESSION VARIABLES LIKE 'character_set%';
SHOW LOCAL VARIABLES is used to display the values of local variables.
For example, we can use the following command to display the value of local time:
SHOW LOCAL VARIABLES LIKE 'time_zone';
In MySQL, query variables are very convenient and important Tool of. By using different query variables, we can optimize query performance and improve MySQL's performance, making it more flexible and efficient. Hope this article can help you.
The above is the detailed content of mysql query variables. For more information, please follow other related articles on the PHP Chinese website!