Mysql – Grant privileges to all users on a single table

mysql-8.0permissions

Is it possible to grant privileges (such as SELECT, INSERT, UPDATE, etc) to all the users for a specific table at the same time?

Here is what I tried but it didn't work out…

GRANT SELECT ON customer TO * @'localhost';

Best Answer

There is a way to do it in previous versions of MySQL referring to anonymous users with the following query, however I think it does not work for your version of MySQL.

GRANT SELECT ON database_name.CUSTOMER TO '' @ '%';

I recommend you create a ROLE and assign this role to all users, after that you can assign a permission to that ROLE and it will have an effect on all the users to whom it is assigned. Administration in this way is much easier. For example:

CREATE ROLE r1;
GRANT r1 TO 'user1' @ '%', 'user2' @ '%', 'user3' @ '%' .....;
GRANT SELECT, INSERT, UPDATE ON database_name.CUSTOMER TO r1;