我需要找到一种方法来列出所有拥有 的数据库用户ALL PRIVILILEGES
(*.*
所有数据库和表)。此外,如果它还可以仅列出那些拥有 的用户,那就太好了GRANT OPTION
。
我最初的想法是将select User from mysql.user where
每个权限字段都设为="Y"
。这会导致查询非常长。还有其他更方便的方法吗?
答案1
MariaDB 上共有 28 个授权:
SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE.
显示具有所有授权的所有用户:
select count(*) as grants, grantee from information_schema.user_privileges group_by grantee having grants >= 28;
要检查它是否正确,你可以检查结果
select * from information_schema.user_privileges;
并比较:)