mysql 中可以使用 show grants for 命令可以显示指定用户拥有的权限。语法如下:
SHOW GRANTS
[FOR user_or_role
[USING role [, role] ...]]
user_or_role: {
user (see Section 6.2.4, “Specifying Account Names”)
| role (see Section 6.2.5, “Specifying Role Names”.
}(1)查看 root 用户的权限信息,如下:
mysql> show grants for 'root'@'%';
+-------------------------------------------------------+
| Grants for root@% |
+-------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'%' |
| GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'root'@'%' |
+-------------------------------------------------------+
2 rows in set (0.05 sec)(2)使用 \G 通过格式的方式查看 root 用户的权限,如下:
mysql> show grants for 'root'@'%' \G
*************************** 1. row ***************************
Grants for root@%: GRANT USAGE ON *.* TO 'root'@'%'
*************************** 2. row ***************************
Grants for root@%: GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'root'@'%'
2 rows in set (0.00 sec)如果用户没有通过 grants 命令授权,使用 show grants for 命令将显示下面信息:
mysql> show grants for 'root'@'%';
1141 - There is no such grant defined for user 'root' on host '%'