首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mysql获取用户的所有表权限

问mysql获取用户的所有表权限
EN

Stack Overflow用户
提问于 2021-07-17 04:34:34
回答 1查看 57关注 0票数 1

我对一个postgresql DB运行以下查询,该查询的目的是返回给定方案中用户没有SELECT权限的所有表

代码语言:javascript
复制
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()函数

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-17 04:40:34

这将在MySQL中工作:

代码语言:javascript
复制
select table_name from information_schema.tables where table_schema='myschema'

表对您的用户是不可见的,也就是说,如果您没有对表的SELECT权限,那么它甚至不会在information_schema.tables中显示为一行。

但更普遍的答案是,假设一个用户正在从超级用户会话中查询,并且可以看到所有的表,那么如何获得对其他任意用户可见的表的列表。

为此,您必须连接到特权表mysql.user、mysql.db和mysql.tables_priv

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68414971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档