Mysql – Apply the select privilege to all users in thesql

MySQLpermissions

I have 30 plus MySQL users their permissions vary from one another.

I want to GRANT SELECT privilege to all of the 30 users. Is there any one command that I can use that can grant select to all 30 users in one shot!

Best Answer

Try this:

mysql> select user,host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| eroom            | localhost |
| musr             | localhost |
| musr             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

mysql> select concat('GRANT SELECT ON *.* to "',user,'"@"',host,'";') into outfile '/tmp/select_script.sql' FROM mysql.user;
Query OK, 4 rows affected (0.00 sec)

mysql> source /tmp/select_script.sql;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)