如何在服务器上使用 MySQL 对所有数据库中的所有表授予 SELECT 权限?
为此,您可以使用以下语法中的 GRANT SELECT 语句 -
GRANT SELECT ON *.* TO 'yourUserName'@'yourHostName';
首先列出所有用户名和主机 -
mysql> select user,host from mysql.user;
这将产生以下输出 -
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Charlie | % | | Robert | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | @UserName@ | localhost | | Adam | localhost | | Adam Smith | localhost | | Chris | localhost | | David | localhost | | Emma | localhost | | Jace | localhost | | James | localhost | | John | localhost | | John Doe | localhost | | Michael | localhost | | Mike | localhost | | Robert | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 26 rows in set (0.00 sec)
以下是执行 GRANT SELECT 的查询 -
mysql> GRANT SELECT ON *.* TO 'hbstudent'@'localhost'; Query OK, 0 rows affected (0.00 sec)
广告