Purpose
This statement is used to set variables.
Syntax
SET [SESSION | GLOBAL] var_and_val_list
var_and_val_list:
var_and_val [,var_and_val ...]
var_and_val:
var_value {TO | =} set_expr_or_default
| var_value = (simple_select)
Parameters
| Parameter | Description |
|---|---|
| SESSION | GLOBAL | Specifies whether to set a session variable or a global variable. The default is to set a session variable. |
| var_value | The name of the variable. |
Examples
Set the user variable
a.obclient> SET @a = 1;Set the global system variable
secure_file_priv, which specifies the path for importing or exporting files.obclient> SET GLOBAL secure_file_priv = '';Set the user variable
proxy_route_policy, which is used to configure the routing policy.obclient> SET @proxy_route_policy = 'follower_first';Set the variable value by using the
SELECTstatement.obclient> CREATE TABLE tbl1(col INT); obclient> INSERT into tbl1 VALUES('1'),('2'),('3'),('4'),('5'); obclient> SET @var1=(SELECT COUNT(*) FROM tbl1);Query the variable value:
obclient> SELECT @var1;The query result is as follows:
+-------+ | @var1 | +-------+ | 5 | +-------+ 1 row in set
