Purpose
This statement is used to set a variable.
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 | Sets a session or global variable. The default is a session-level variable. |
| var_value | Variable name. |
Examples
Set the user variable
a.obclient> SET @a = 1;Set the global system variable
secure_file_priv, which controls the accessible paths for importing or exporting to 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';Use the
SELECTstatement to set variable values.obclient> CREATE TABLE tbl1(col INT); obclient> INSERT into tbl1 VALUES('1'),('2'),('3'),('4'),('5'); obclient> SET @var1=(SELECT COUNT(*) FROM tbl1);Query variable value:
obclient> SELECT @var1;The query result is as follows:
+-------+ | @var1 | +-------+ | 5 | +-------+ 1 row in set