Reputation: 25
I have made a database called hospitals but when I try and grant my user privileges to the database I get an error back.
My code:
input:
CREATE USER 'axel'@'%' IDENTIFIED BY '123'
output:
Query OK, 0 rows affected (0.19 sec)
input:
grant all on hospitals.* to 'axel'@'localhost';
output:
You are not allowed to create a user with GRANT
How do I fix this? I have tried different things but nothing seems to work and I keep getting the same error message.
Upvotes: 2
Views: 2697
Reputation: 563021
The user 'axel'@'%'
is not the same user as 'axel'@'localhost'
.
You created the former with CREATE USER, then you try to use grant for the latter user, but that user doesn't exist.
MySQL used to allow you to create a user implicitly by granting privileges, but they disabled that specifically for cases like yours. The problem being that since you didn't realize these are different users, your GRANT would have inadvertently created 'axel'@'localhost'
as a new user with no password. This was considered a security risk.
Upvotes: 6