SET Syntax

The general syntax of SET statement is :
SET variable_assignment [,
variable_assignment] ...
variable_assignment : user_var_name = expr | [GLOBAL | SESSION] system_var_name = expr
| [@@global. | @@session. | @@]system_var_name = expr
SET statement is used for assigning the values for different types of variables which affects the operation of your client or the server. In this section we are describing you the use of SET statement to assign the values for system variables or user variables.
Some variants of SET syntax are used in other contexts:
- SET PASSWORD statement is used to assign the account passwords. Example :
mysql> SET PASSWORD FOR chand=PASSWORD('chand2');
Query OK, 0 rows affected (0.00 sec)
|
- SET TRANSACTION ISOLATION LEVEL is used to set the isolation level for transaction process. Example
:
mysql> SET GLOBAL TRANSACTION ISOLATION LEVEL
-> REPEATABLE READ;
Query OK, 0 rows affected (0.00 sec)
|
-
SET is used store procedure or function for assigning the values to local variables. Example
:
mysql> delimiter //
mysql> CREATE PROCEDURE Setdemo(OUT a VARCHAR(30))
-> SET a='Demo of Set Syntax';
-> //
Query OK, 0 rows affected (0.20 sec)
mysql> delimiter ;
mysql> CALL Setdemo(@a);
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @a;
+--------------------+
| @a |
+--------------------+
| Demo of Set Syntax |
+--------------------+
1 row in set (0.01 sec)
|
A user variable can written as @variable_name and it
can set as follows :
mysql> SET @b='Rahul';
Query OK, 0 rows affected (0.03 sec)
mysql> SELECT @b;
+-------+
| @b |
+-------+
| Rahul |
+-------+
1 row in set (0.00 sec)
|
Many system variables are dynamic and while the server running it can be change by using of SET statement. For changing a system variable by SET statement refer it as variable_name optionally it can be preceded by a
modifier.
- For specifying explicitly a variable is a global variable we can precede it by GLOBAL or @@global… But for this you must have have super privilege.
- For specifying explicitly a variable is a session variable we can precede it by SESSION or @@session or @@. For this you don’t require any special privilege but a client can change its own session variable only. LOCAL and @@local. are synonyms for SESSION and @@session..
- If no modifier is present, SET changes the session variable.
We can get the list of system variable names and values by the SHOW VARIABLES statement.
The following list describes you the options which have non standard syntax and these option are not displayed by SHOW variables, you can obtain their values by SELECT.
The lettercase of these options does not matter.

|