System variables vs Local Variables in MySQL?

MySQLMySQLi Database

The local variable has the scope for only a set of statements or block of statement. Whenever a set of statements or block of statement has completed then local variable goes out of scope.

For Example:

Local variable can be used in stored procedure, function etc. It is used with the DECLARE keyword.

The syntax is as follows to local variables.

DECLARE yourVariableName dataType;

The global variables or system variables has the scope across connections until server restart. It is set using GLOBAL keyword. The syntax is as follows:

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

If you know port number then you can use system variable @@port using select statement. The query is as follows:

mysql> select @@port;

The following is the output:

+--------+
| @@port |
+--------+
| 3306   |
+--------+
1 row in set (0.00 sec)
raja
Published on 25-Feb-2019 15:07:43
Advertisements