
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
System variables vs Local Variables in MySQL?
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;
Output
The following is the output −
+--------+ | @@port | +--------+ | 3306 | +--------+ 1 row in set (0.00 sec)
- Related Articles
- User-defined variables vs Local Variables in MySQL?
- System variables vs User-defined variables in MySQL?
- Member variables vs Local variables in Java
- Global vs Local variables in Python
- What are class variables, instance variables and local variables in Java?
- Local variables in Java
- What are local variables and global variables in C++?
- Final local variables in C#
- How can local variables be used in MySQL stored procedure?
- Global and Local Variables in Python?
- Global and Local Variables in Java
- What are local variables in C++?
- Global and Local Variables in C#
- What are Local Scope Variables in Postman?
- How to Display System Variables of MySQL Server?

Advertisements