SHOW GRANTS

SHOW GRANTS 语句用于显示与用户关联的权限列表。与在 MySQL 中一样,USAGE 权限表示登录 TiDB 的能力。

语法图

ShowGrantsStmt

SHOW GRANTS - 图1

Username

SHOW GRANTS - 图2

RolenameList

SHOW GRANTS - 图3

  1. ShowGrantsStmt ::=
  2. "SHOW" "GRANTS" ("FOR" Username ("USING" RolenameList)?)?
  3. Username ::=
  4. "CURRENT_USER" ( "(" ")" )?
  5. | Username ("@" Hostname)?
  6. RolenameList ::=
  7. Rolename ("@" Hostname)? ("," Rolename ("@" Hostname)? )*

示例

  1. SHOW GRANTS;
  1. +-------------------------------------------+
  2. | Grants for User |
  3. +-------------------------------------------+
  4. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' |
  5. +-------------------------------------------+
  6. 1 row in set (0.00 sec)
  1. SHOW GRANTS FOR 'u1';
  1. ERROR 1141 (42000): There is no such grant defined for user 'u1' on host '%'
  1. CREATE USER u1;
  1. Query OK, 1 row affected (0.04 sec)
  1. GRANT SELECT ON test.* TO u1;
  1. Query OK, 0 rows affected (0.04 sec)
  1. SHOW GRANTS FOR u1;
  1. +------------------------------------+
  2. | Grants for u1@% |
  3. +------------------------------------+
  4. | GRANT USAGE ON *.* TO 'u1'@'%' |
  5. | GRANT Select ON test.* TO 'u1'@'%' |
  6. +------------------------------------+
  7. 2 rows in set (0.00 sec)

MySQL 兼容性

SHOW GRANTS 语句与 MySQL 完全兼容。如发现任何兼容性差异,请尝试 TiDB 支持资源

另请参阅