Purpose
You can use this statement 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 or global variable. A session variable is set by default. |
| var_value | The name of the variable. |
Examples
Set a user variable
a.obclient> SET @a = 1;Set a global system variable
secure_file_priv, which specifies the path accessible when you import/export data to/from a file.obclient> SET GLOBAL secure_file_priv = '';Set a user variable
proxy_route_policy, which specifies the routing strategy.obclient> SET @proxy_route_policy = 'follower_first';Use the
SELECTstatement to set variable values.obclient> CREATE TABLE tbl1(col INT); Query OK, 0 rows affected obclient> INSERT into tbl1 VALUES('1'),('2'),('3'),('4'),('5'); Query OK, 5 rows affected Records: 5 Duplicates: 0 Warnings: 0 obclient> SET @var1=(SELECT COUNT(*) FROM tbl1); Query OK, 0 rows affected