How to GRANT SELECT ON all tables in all databases on a server with MySQL?


For this, you can use GRANT SELECT statement as in the below syntax −

GRANT SELECT ON *.* TO 'yourUserName'@'yourHostName';

First list all the user names along with host −

mysql> select user,host from mysql.user;

This will produce the following output −

+------------------+-----------+
| 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)

Here is the query to implement GRANT SELECT −

mysql> GRANT SELECT ON *.* TO 'hbstudent'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Updated on: 24-Dec-2019

990 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements