如何显示为MySQL用户定义的授权?
为此,请使用SHOWGRANTS。以下是语法-
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)
让我们使用SHOWGRANTS显示特定用户的授权-
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)
上面的SHOWGRANTS示例返回了主机上用户Robert的授予信息,MySQL假定该信息为'%'。