我对一个postgresql DB运行以下查询,该查询的目的是返回给定方案中用户没有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()函数
发布于 2021-07-17 04:40:34
这将在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 nullhttps://stackoverflow.com/questions/68414971
复制相似问题