[英]mysql get all table privileges for a user
我有以下针对 postgresql 数据库运行的查询,其目的是返回给定模式中用户没有 SELECT 权限的所有表
select table_name from information_schema.tables
where table_schema=myschema
except
SELECT DISTINCT table_name FROM information_schema.table_privileges
WHERE has_table_privilege(table_schema || '.' || table_name, 'SELECT');
我将如何构建用于 mysql 数据库的类似查询? mysql 没有has_table_privilege()
函数
这将在 MySQL 中工作:
select table_name from information_schema.tables where table_schema='myschema'
一个表对您的用户不可见,也就是说,如果您对该表没有 SELECT 权限,它甚至不会在information_schema.tables
显示为一行。
但更一般的答案是如何获得对其他任意用户可见的表列表,假设一个人正在从超级用户会话中查询并且可以看到所有表。
为此,您必须加入权限表mysql.user
、 mysql.db
和mysql.tables_priv
:
select i.table_schema, i.table_name from information_schema.tables i
left join mysql.user u on u.user='testuser' and u.select_priv = 'Y'
left join mysql.db d on d.user = 'testuser' and d.db = i.table_schema and d.select_priv = 'Y'
left join mysql.tables_priv t on t.user = 'testuser' and t.db = i.table_schema and t.table_name = i.table_name and find_in_set('Select', t.table_priv)
where coalesce(u.user, d.user, t.user) is not null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.