> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# SET

> SET 为 数据库 设置指定的系统变量或用户自定义变量。

## 功能

为 数据库 设置指定的系统变量或用户自定义变量。您可以通过 [SHOW VARIABLES](/documents/cn/4.2/sql-reference/sql-statements/cluster-management/config_vars/SHOW_VARIABLES.md) 查看 数据库 的系统变量。有关系统变量的详细信息，请参阅[系统变量](/documents/cn/4.2/sql-reference/System_variable.md)。有关用户自定义变量的详细信息，请参阅\[用户自定义变量]\(../../../../r../../../user\_defined\_variables.md

**Tip**

该操作不需要权限。

## 语法

```SQL theme={null}
SET [ GLOBAL | SESSION ] <variable_name> = <value> [, <variable_name> = <value>] ...
```

## 参数说明

| **参数** | **说明** |
| - | - |
| 修饰符：<ul><li>GLOBAL</li><li>SESSION</li></ul> | <ul><li>使用 `GLOBAL` 修饰符，该语句设置该变量值为全局变量值。</li><li>使用 `SESSION` 修饰符，该语句设置该变量值对当前连接有效。您可以使用 `LOCAL` 替代 `SESSION`。</li><li>如不指定修饰符，默认值为 `SESSION`。</li></ul>有关全局变量和会话变量的详细信息，请参阅 [系统变量](/documents/cn/4.2/sql-reference/System_variable.md)。 **说明** 仅拥有 System 级 OPERATE 权限的用户才能设置全局变量。 |
| variable\_name | 变量名。 |
| value | 变量值。 |

## 示例

示例一：在当前会话内设置 `time_zone` 为 `Asia/Shanghai`。

```Plain theme={null}
mysql> SET time_zone = "Asia/Shanghai";
Query OK, 0 rows affected (0.00 sec)
```

示例二：全局设置 `query_mem_limit` 为 `2147483648`。

```Plain theme={null}
mysql> SET GLOBAL query_mem_limit = 2147483648;
Query OK, 0 rows affected (0.00 sec)
```

示例三：同时设置多个全局变量。需要在所有变量名前添加 `GLOBAL` 关键字。

```Plain theme={null}
mysql> SET 
       GLOBAL query_mem_limit = 2147483648,
       GLOBAL time_zone = "Asia/Shanghai";
Query OK, 0 rows affected (0.00 sec)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.