[SQL] MariaDB & MySQL 用户权限的显示

内容一:显示当前用户的所有权限

> show grants;

或者:

> show grants for current_user();

内容二:显示某个用户的所有权限

> show grants root;

(补充:这里以显示 root 用户的所有权限为例)

内容三:显示所有用户的所有权限

3.1 合成显示所有用户的所有权限的 SQL 语句

> select concat('show grants for ''',user,'''@''',host,''';') as query from mysql.user;
+-------------------------------------+
| query                               |
+-------------------------------------+
| show grants for 'root'@'127.0.0.1'; |
| show grants for 'root'@'::1';       |
| show grants for 'root'@'localhost'; |
| show grants for 'root'@'mysql';     |
+-------------------------------------+
4 rows in set (0.000 sec) 

3.2 显示所有用户的所有权限

> show grants for 'root'@'127.0.0.1';
show grants for 'root'@'::1';
show grants for 'root'@'localhost';
show grants for 'root'@'mysql';

(补充:这里使用的 SQL 语句是上个步骤 3.1 合成的)