USER_PRIVILEGES

USER_PRIVILEGES 表提供了关于全局权限的信息。该表的数据根据 mysql.user 系统表生成。

USE INFORMATION_SCHEMA; DESC USER_PRIVILEGES;

输出结果如下:

+----------------+--------------+------+------+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+------+---------+-------+ | GRANTEE | varchar(81) | YES | | NULL | | | TABLE_CATALOG | varchar(512) | YES | | NULL | | | PRIVILEGE_TYPE | varchar(64) | YES | | NULL | | | IS_GRANTABLE | varchar(3) | YES | | NULL | | +----------------+--------------+------+------+---------+-------+ 4 rows in set (0.00 sec)

查看 USER_PRIVILEGES 表的信息:

SELECT * FROM USER_PRIVILEGES;

输出结果如下:

+------------+---------------+-------------------------+--------------+ | GRANTEE | TABLE_CATALOG | PRIVILEGE_TYPE | IS_GRANTABLE | +------------+---------------+-------------------------+--------------+ | 'root'@'%' | def | SELECT | YES | | 'root'@'%' | def | INSERT | YES | | 'root'@'%' | def | UPDATE | YES | | 'root'@'%' | def | DELETE | YES | | 'root'@'%' | def | CREATE | YES | | 'root'@'%' | def | DROP | YES | | 'root'@'%' | def | PROCESS | YES | | 'root'@'%' | def | REFERENCES | YES | | 'root'@'%' | def | ALTER | YES | | 'root'@'%' | def | SHOW DATABASES | YES | | 'root'@'%' | def | SUPER | YES | | 'root'@'%' | def | EXECUTE | YES | | 'root'@'%' | def | INDEX | YES | | 'root'@'%' | def | CREATE USER | YES | | 'root'@'%' | def | CREATE TABLESPACE | YES | | 'root'@'%' | def | TRIGGER | YES | | 'root'@'%' | def | CREATE VIEW | YES | | 'root'@'%' | def | SHOW VIEW | YES | | 'root'@'%' | def | CREATE ROLE | YES | | 'root'@'%' | def | DROP ROLE | YES | | 'root'@'%' | def | CREATE TEMPORARY TABLES | YES | | 'root'@'%' | def | LOCK TABLES | YES | | 'root'@'%' | def | CREATE ROUTINE | YES | | 'root'@'%' | def | ALTER ROUTINE | YES | | 'root'@'%' | def | EVENT | YES | | 'root'@'%' | def | SHUTDOWN | YES | | 'root'@'%' | def | RELOAD | YES | | 'root'@'%' | def | FILE | YES | | 'root'@'%' | def | CONFIG | YES | | 'root'@'%' | def | REPLICATION CLIENT | YES | | 'root'@'%' | def | REPLICATION SLAVE | YES | +------------+---------------+-------------------------+--------------+ 31 rows in set (0.00 sec)

USER_PRIVILEGES 表中列的含义如下:

  • GRANTEE:被授权的用户名称,格式为 'user_name'@'host_name'
  • TABLE_CATALOG:表所属的目录的名称。该值始终为 def
  • PRIVILEGE_TYPE:被授权的权限类型,每行只列一个权限。
  • IS_GRANTABLE:如果用户有 GRANT OPTION 的权限,则为 YES,否则为 NO

文档内容是否有帮助?