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.
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;
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!