SHOW GRANTS

This statement shows a list of privileges associated with a user. As in MySQL, the USAGE privileges denotes the ability to login to TiDB.

Synopsis

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)? )*

Examples

  1. mysql> SHOW GRANTS;
  2. +-------------------------------------------+
  3. | Grants for User |
  4. +-------------------------------------------+
  5. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' |
  6. +-------------------------------------------+
  7. 1 row in set (0.00 sec)
  8. mysql> SHOW GRANTS FOR 'u1';
  9. ERROR 1141 (42000): There is no such grant defined for user 'u1' on host '%'
  10. mysql> CREATE USER u1;
  11. Query OK, 1 row affected (0.04 sec)
  12. mysql> GRANT SELECT ON test.* TO u1;
  13. Query OK, 0 rows affected (0.04 sec)
  14. mysql> SHOW GRANTS FOR u1;
  15. +------------------------------------+
  16. | Grants for u1@% |
  17. +------------------------------------+
  18. | GRANT USAGE ON *.* TO 'u1'@'%' |
  19. | GRANT Select ON test.* TO 'u1'@'%' |
  20. +------------------------------------+
  21. 2 rows in set (0.00 sec)

MySQL compatibility

The SHOW GRANTS statement in TiDB is fully compatible with MySQL. If you find any compatibility differences, report a bug.

See also