# **SHOW GRANTS**

## **语法说明**

使用 `SHOW GRANTS` 语句显示用户的所有授权信息。`SHOW GRANTS` 语句显示使用 `GRANT` 命令分配给用户的权限。

使用 `SHOW GRANTS` 语句需要拥有查询 *mo_catalog* 库下所有表的 `SELECT` 权限，但显示当前用户的权限和角色除外。

要为 `SHOW GRANTS` 命名帐户或角色，即使用与 `GRANT` 语句相同的格式，例如：

```sql
show grants for 'root'@'localhost';
```

## **语法结构**

```sql
SHOW GRANTS FOR {username[@hostname] | rolename};
```

## **示例**

```text
create role role1;
grant all on table *.* to role1;
grant create table, drop table on database *.* to role1;
create user user1 identified by 'pass1';
grant role1 to user1;
> show grants for 'user1'@'localhost';
+--------------------------------------------------------+
| Grants for user1@localhost                             |
+--------------------------------------------------------+
| GRANT connect ON account  `user1`@`localhost`          |
| GRANT table all ON table *.* `user1`@`localhost`       |
| GRANT create table ON database *.* `user1`@`localhost` |
| GRANT drop table ON database *.* `user1`@`localhost`   |
+--------------------------------------------------------+
4 rows in set (0.00 sec)

mysql> show grants for ROLE role1;
+--------------------------------------------+
| Grants for role1                           |
+--------------------------------------------+
| GRANT table all ON table *.* `role1`       |
| GRANT create table ON database *.* `role1` |
| GRANT drop table ON database *.* `role1`   |
+--------------------------------------------+
3 rows in set (0.00 sec)
```
