列出mysql中所有具有dml权限的用户

p5fdfcr1  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(286)

我需要列出在模式、表或列级别定义的服务器上具有任何dml访问权限的所有用户。我有以下问题。有没有更优雅的解决方案?

select host, 
       db, user, 
       '*' tables, 
       '*' columns, 
       'schema' priv_defined_at 
from mysql.db d
where (Insert_priv = 'Y' 
    or Update_priv = 'Y'
    or Delete_priv = 'Y' 
    or Create_priv = 'Y' 
    or Grant_priv = 'Y' 
    or Index_priv = 'Y' 
    or Alter_priv = 'Y' 
    or Create_tmp_table_priv = 'Y' 
    or Create_view_priv = 'Y' 
    or Create_routine_priv = 'Y' 
    or Alter_routine_priv = 'Y' 
    or Event_priv = 'Y' 
    or Trigger_priv = 'Y')
union all
select host, 
       db, 
       user, 
       table_name, 
       '*' columns, 
       'table' defined_at 
from mysql.tables_priv
where (Table_priv in ('Insert','Update','Delete','Create','Drop','Index','Alter','Create View','Trigger'))
union all
(select host, 
        db, 
        user, 
        table_name, 
        group_concat(column_name separator ', '), 
        'column' defined_at 
from mysql.columns_priv 
where (Column_priv like '%insert%' 
    or Column_priv like '%delete%' 
    or Column_priv like '%update%'
    or Column_priv like '%alter%')
group by 1, 2, 3, 4)
order by user;

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题