Home  >  Article  >  Database  >  System variables and local variables in MySQL?

System variables and local variables in MySQL?

王林
王林forward
2023-09-15 16:21:02694browse

MySQL 中的系统变量与局部变量?

The scope of local variables is limited to a set of statements or statement blocks. Whenever a set of statements or block of statements completes, local variables go out of scope.

For example

Local variables can be used in stored procedures, functions, etc. Used together with the DECLARE keyword.

The syntax of local variables is as follows.

DECLARE yourVariableName dataType;

Global or system variables have cross-connection scope until the server is restarted. It is set using the GLOBAL keyword. The syntax is as follows -

SET GLOBAL max_connections=value;
OR
SET @@global.max_connections=value;

If you know the port number, you can use the system variable @@port using the select statement. The query is as follows -

mysql> select @@port;

Output

The following is the output -

+--------+
| @@port |
+--------+
| 3306 |
+--------+
1 row in set (0.00 sec)

The above is the detailed content of System variables and local variables in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete