Home > Database > Mysql Tutorial > mysql query variables

mysql query variables

王林
Release: 2023-05-13 18:47:07
Original
1807 people have browsed it

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.

  1. @@global.variable_name

@@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;

  1. @@session.variable_name

@@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;

  1. @@local. variable_name

@@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();

  1. SET variable_name = value

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;

  1. SET SESSION variable_name = value

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';

  1. SET LOCAL variable_name = value

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();

  1. SHOW GLOBAL VARIABLES

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%';

  1. SHOW SESSION VARIABLES

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%';

  1. SHOW LOCAL VARIABLES

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template