如何显示为 MySQL 用户定义的授予权限?
为此使用 SHOW GRANTS。以下是语法 -
SHOW GRANTS FOR 'yourUserName'@'yourHostName';
让我们显示 MySQL.user 表中的用户名和主机名。
mysql> select user,host from MySQL.user;
这将输出以下内容 -
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Charlie | % | | Robert | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | @UserName@ | localhost | | Adam Smith | localhost | | Chris | localhost | | David | localhost | | James | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 20 rows in set (0.00 sec)
让我们使用 SHOW GRANTS 显示特定用户的授予权限 -
mysql> SHOW GRANTS FOR 'Robert'@'%
这将输出以下内容 -
+----------------------------------------------------------------------+ | Grants for Robert@% | +----------------------------------------------------------------------+ | GRANT USAGE ON *.* TO `Robert`@`%` | | GRANT ALL PRIVILEGES ON `sample`.* TO `Robert`@`%` WITH GRANT OPTION | | GRANT EXECUTE ON `web`.* TO `Robert`@`%` | +----------------------------------------------------------------------+ 3 rows in set (0.05 sec)
上面,SHOW GRANTS 示例返回主机上用户 Robert 的授予权限信息,其中 MySQL 假定为 '%'
广告