mrakona
mrakona

Reputation: 81

Cannot Grant select on mysql 8.0.17

I want to grant select privilege to user from every host, but getting an error, you're not allow to create a user

mysql>GRANT SELECT ON *.* TO 'alice'@'%' WITH GRANT OPTION;

ERROR 1410 (42000): You are not allowed to create a user with GRANT

I don't want to create a new user, for that I used command CREATE USER

I tried to create a new user but the grant command also failed.

Upvotes: 7

Views: 6671

Answers (2)

hungl
hungl

Reputation: 101

I just had the same issue.

But my problem was that I made a mistake in CREATE USER query. I wanted to create grafana user, but executed the following query: CREATE USER grafan IDENTIFIED BY '<password>'; (Note that I created grafan user here instead of grafana)

Then, when I executed query GRANT SELECT ON mydb.* TO grafana@'%'; I got an error ERROR 1410 (42000): You are not allowed to create a user with GRANT. There was no mention that user grafana does not exist.

I spent about 20 minutes to figure out what I was doing wrong.

So if you are reading this, just check that you had correctly created your user. Hope this will help someone.

Upvotes: 3

Alvimar
Alvimar

Reputation: 498

A good idea (and a good practice) in this MySql Version (8 and above) is to config ROLES and then set the users for it, like this good article (read it, is very good!).

You'll can set your role to many users.

Something like this:

1 - Create the role:

create ROLE name_of_your_role;

2 - Set the necessary privileges to the ROLE, and remember, in this MySql version you dont need of Flush Privileges. Example (change mydatabase expression for your database name or wildcard, like you need):

grant alter,create,delete,drop,index,insert,select,update,trigger,alter
 routine,create routine, execute, create temporary tables 
on mydatabase.* to 'name_of_your_role';

3 - Grant the role for your user:

grant 'name_of_your_role' to 'alice';

4 - Set this role as default to your user:

set default role 'name_of_your_role' to 'alice';

Upvotes: 3

Related Questions