Skip to content

Commit

Permalink
resource_control: add a example to reset user resource group to defau…
Browse files Browse the repository at this point in the history
…lt value (#13649)
  • Loading branch information
glorv authored Apr 13, 2023
1 parent 7cf9d9b commit 00b1659
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
39 changes: 37 additions & 2 deletions sql-statements/sql-statement-alter-user.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ SHOW CREATE USER 'newuser';
1 row in set (0.00 sec)
```

{{< copyable "sql" >}}
### 修改用户基本信息

修改用户 `newuser` 的密码:

```sql
ALTER USER 'newuser' IDENTIFIED BY 'newnewpassword';
Expand All @@ -87,7 +89,7 @@ SHOW CREATE USER 'newuser';
1 row in set (0.00 sec)
```

{{< copyable "sql" >}}
锁定用户 `newuser`

```sql
ALTER USER 'newuser' ACCOUNT LOCK;
Expand Down Expand Up @@ -165,6 +167,8 @@ ALTER USER 'newuser' PASSWORD REUSE INTERVAL 90 DAY;
Query OK, 0 rows affected (0.02 sec)
```

### 修改用户绑定的资源组

通过 `ALTER USER ... RESOURCE GROUP` 修改用户 `newuser` 的资源组到 `rg1`

```sql
Expand All @@ -175,6 +179,37 @@ ALTER USER 'newuser' RESOURCE GROUP rg1;
Query OK, 0 rows affected (0.02 sec)
```

查看当前用户绑定的资源组:

```sql
SELECT USER, JSON_EXTRACT(User_attributes, "$.resource_group") FROM mysql.user WHERE user = "newuser";
```

```
+---------+---------------------------------------------------+
| USER | JSON_EXTRACT(User_attributes, "$.resource_group") |
+---------+---------------------------------------------------+
| newuser | "rg1" |
+---------+---------------------------------------------------+
1 row in set (0.02 sec)
```

取消用户绑定的资源组,即将用户绑定的资源组设置为空。取消后,用户会绑定到 `default` 资源组。

```sql
ALTER USER 'newuser' RESOURCE GROUP ``;
SELECT USER, JSON_EXTRACT(User_attributes, "$.resource_group") FROM mysql.user WHERE user = "newuser";
```

```
+---------+---------------------------------------------------+
| USER | JSON_EXTRACT(User_attributes, "$.resource_group") |
+---------+---------------------------------------------------+
| newuser | "" |
+---------+---------------------------------------------------+
1 row in set (0.02 sec)
```

## 另请参阅

* [Security Compatibility with MySQL](/security-compatibility-with-mysql.md)
Expand Down
1 change: 1 addition & 0 deletions sql-statements/sql-statement-create-resource-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ MySQL 也支持 [CREATE RESOURCE GROUP](https://dev.mysql.com/doc/refman/8.0/en/

* [DROP RESOURCE GROUP](/sql-statements/sql-statement-drop-resource-group.md)
* [ALTER RESOURCE GROUP](/sql-statements/sql-statement-alter-resource-group.md)
* [ALTER USER RESOURCE GROUP](/sql-statements/sql-statement-alter-user.md#修改用户绑定的资源组)
* [RU](/tidb-resource-control.md#什么是-request-unit-ru)
4 changes: 2 additions & 2 deletions tidb-resource-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ Request Unit (RU) 是 TiDB 对 CPU、IO 等系统资源的统一抽象的单位,

TiDB 支持如下三个级别的资源组设置:

- 用户级别。通过 [`CREATE USER`](/sql-statements/sql-statement-create-user.md) 或 [`ALTER USER`](/sql-statements/sql-statement-alter-user.md) 语句将用户绑定到特定的资源组。绑定后,对应的用户新创建的会话会自动绑定对应的资源组。
- 用户级别。通过 [`CREATE USER`](/sql-statements/sql-statement-create-user.md) 或 [`ALTER USER`](/sql-statements/sql-statement-alter-user.md#修改用户绑定的资源组) 语句将用户绑定到特定的资源组。绑定后,对应的用户新创建的会话会自动绑定对应的资源组。
- 会话级别。通过 [`SET RESOURCE GROUP`](/sql-statements/sql-statement-set-resource-group.md) 设置当前会话使用的资源组。
- 语句级别。通过 [`RESOURCE_GROUP()`](/optimizer-hints.md#resource_groupresource_group_name) 设置当前语句使用的资源组。
- 语句级别。通过 [`RESOURCE_GROUP()`](/optimizer-hints.md#resource_groupresource_group_name) Optimizer Hint 设置当前语句使用的资源组。

#### 将用户绑定到资源组

Expand Down

0 comments on commit 00b1659

Please sign in to comment.