---
title: "间接授权 - OceanBase 数据库 V4.5.0 | OceanBase 文档中心"
description: 间接授权 用户的权限，包含直接授予的权限，也包含授予角色后，通过角色间接获得的权限。大部分操作需要的权限，不论是直接授予的还是通过角色间接拥有的权限，都可以满足条件。 通过被授予角色间接获得权限 通过将角色授予用户或用户的其他角色，被授予了角色的用户就会间接获得该角色所包含的权限。 注意 用户可以始终使用直接被授予的…
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*P8CuR4UJ_FkAAAAAAAAAAAAADiGDAQ/original) OceanBase 数据库分布式版 - V 4.5.0

# 间接授权

更新时间：2026-04-05 11:29:06

[编辑](https://github.com/oceanbase/oceanbase-doc/edit/V4.5.0/zh-CN/600.manage/500.security-and-permissions/300.access-control/200.user-and-permission/200.permission-of-mysql-mode/350.indirect-authority-of-mysql-mode.md)  

用户的权限，包含直接授予的权限，也包含授予角色后，通过角色间接获得的权限。大部分操作需要的权限，不论是直接授予的还是通过角色间接拥有的权限，都可以满足条件。

## 通过被授予角色间接获得权限

通过将角色授予用户或用户的其他角色，被授予了角色的用户就会间接获得该角色所包含的权限。

#### 注意

用户可以始终使用直接被授予的权限，但不一定可以使用通过角色间接获得的权限，用户只能使用在当前会话中被激活的角色的权限。有关激活角色的详细操作，请参见 [激活角色](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000004480425)。

### 前提条件

将角色授予其他用户或角色时，当前用户必须拥有被授予的角色，并且拥有 `ADMIN OPTION` 权限，才能授权成功。查看当前用户所拥有的权限的相关操作请参见 [查看用户权限](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000004479237)。

### 背景信息

假设当前有一个用户 `test1`，并且其已经被授予了一个角色 `employee`。查看 `employee` 角色包含的权限，语句如下：

```shell
obclient [oceanbase]> SHOW GRANTS FOR employee;

```

结果如下：

```shell
+--------------------------------------------------+
| Grants for employee@%                            |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO 'employee'                 |
| GRANT UPDATE, SELECT ON `dbtest`.* TO 'employee' |
+--------------------------------------------------+
2 rows in set

```

当前用户有一个 `developer` 角色，查看 `developer` 角色包含的权限，语句如下：

```shell
obclient [oceanbase]> SHOW GRANTS FOR developer;

```

结果如下：

```shell
+------------------------------------------+
| Grants for developer@%                   |
+------------------------------------------+
| GRANT ALTER SYSTEM ON *.* TO 'developer' |
+------------------------------------------+
1 row in set

```

### 操作示例

现在需要将角色 `developer` 中所有操作权限授予用户 `test1`，您可以通过以下方式来实现间接授权：

- 将角色授予用户

     1. 当前用户将角色 `developer` 授予用户 `test1`。

       ```shell
       obclient [oceanbase]> GRANT developer TO test1;

       ```

       如果希望用户后续可以转授该角色，可以添加 `WITH ADMIN OPTION` 子句。

       ```shell
       obclient [oceanbase]> GRANT developer TO test1 WITH ADMIN OPTION;

       ```
     2. 通过 `SHOW GRANTS ... USING` 语句查看用户通过 `developer` 获得的权限。

       ```shell
       obclient [oceanbase]> SHOW GRANTS FOR test1 USING developer;

       ```

       结果如下：

       ```shell
       +-----------------------------------------------------+
       | Grants for test1@%                                  |
       +-----------------------------------------------------+
       | GRANT ALTER SYSTEM ON *.* TO 'test1'                |
       | GRANT `developer`@`%`,`employee`@`%` TO `test1`@`%` |
       +-----------------------------------------------------+
       2 rows in set

       ```
 - 将角色授予用户的角色

     1. 将角色 `developer` 授予角色 `employee`.

       ```shell
       obclient [oceanbase]> GRANT developer TO employee;

       ```
     2. 可以通过 `SHOW GRANTS ... USING` 语句查看用户 `test1` 通过 `employee` 获得的权限。

       ```shell
       obclient [oceanbase]> SHOW GRANTS FOR test1 USING employee;

       ```

       结果如下：

       ```shell
       +-----------------------------------------------+
       | Grants for test1@%                            |
       +-----------------------------------------------+
       | GRANT ALTER SYSTEM ON *.* TO 'test1'          |
       | GRANT UPDATE, SELECT ON `dbtest`.* TO 'test1' |
       | GRANT `employee`@`%` TO `test1`@`%`           |
       +-----------------------------------------------+
       3 rows in set

       ```

       根据查询结果可知，用户 `test1` 通过 `employee` 角色获得了 `ALTER SYSTEM` 权限，再查看 `employee` 被授予的角色或权限。

       ```shell
       obclient [(none)]> SHOW GRANTS FOR employee;

       ```

       结果如下，可以看出，`ALTER SYSTEM` 权限是通过 `developer` 角色获得。

       ```shell
       +--------------------------------------------------+
       | Grants for employee@%                            |
       +--------------------------------------------------+
       | GRANT USAGE ON *.* TO 'employee'                 |
       | GRANT UPDATE, SELECT ON `dbtest`.* TO 'employee' |
       | GRANT `developer`@`%` TO `employee`@`%`          |
       +--------------------------------------------------+
       3 rows in set

       ```

## 相关文档

有关角色相关的更多操作，请参见 [角色管理](https://www.oceanbase.com/docs/common-oceanbase-database-cn-1000000004480429)。

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
