MySQL 数据库的所有 table 和列级权限的列表

List of all table and column level privileges for a MySQL database

列出 MySQL 数据库的所有 table 级和列级权限的最简单方法是什么?我需要知道为特定数据库授予了何种级别的自定义访问权限,以及哪些用户对某些 tables and/or 列的访问权限进行了微调。

使用 percona 工具包中的 pt-show-grants

要列出table级权限,可以查询the INFORMATION_SCHEMA.TABLE_PRIVILEGES table.

The TABLE_PRIVILEGES table has these columns:

  • GRANTEE : the name of the account to which the privilege is granted, in 'user_name'@'host_name' format.

  • [...]

  • TABLE_NAME : the name of the table.

  • PRIVILEGE_TYPE : The privilege granted. The value can be any privilege that can be granted at the table level; [...] . Each row lists a single privilege, so there is one row per table privilege held by the grantee.

要列出列级权限,请查看 the INFORMATION_SCHEMA.COLUMN_PRIVILEGES table

特定数据库的所有 table/column 级别权限:

SELECT * FROM `INFORMATION_SCHEMA`.`TABLE_PRIVILEGES` WHERE TABLE_SCHEMA = 'my_database';
SELECT * FROM `INFORMATION_SCHEMA`.`COLUMN_PRIVILEGES` WHERE TABLE_SCHEMA = 'my_database';