I am trying to execute this queries -
DROP DATABASE IF EXISTS `hotel`;
GRANT USAGE ON *.* TO \'user\'@\'localhost\';
DROP USER \'user\'@\'localhost\';
CRE
I thought that Grant usage create new user if user does not exist. What is wrong?
In previous versions of mysql that was the case. See this answer if you want to do it the new way. If you would like to modify your system settings to make it work the way it used to, read on. However, note that this is a deprecated behavior, as the linked documentation states that
NO_AUTO_CREATE_USER will be removed in a future MySQL release, at which point its effect will be enabled at all times (GRANT will not create accounts)
From the documentation, you can set an option to allow mysql to create a user if it does not exist.
NO_AUTO_CREATE_USER
Prevent the GRANT statement from automatically creating new users if it would otherwise do so, unless a nonempty password also is specified.
To set the option:
You can change the SQL mode at runtime by using a SET [GLOBAL|SESSION] sql_mode='modes' statement to set the sql_mode system value.
Try to add to the end of the script:
FLUSH PRIVILEGES;
I got the same error with
grant all on newdb.* to newuser@localhost;
solved with 'identified by':
grant all on newdb.* to newuser@localhost identified by 'password';
Run from Root user:
grant all privileges on *.* to 'user'@'localhost' identified by '';
EDIT
Example
mysql> grant all privileges on *.* to 'user'@'localhost' identified by 'user';
mysql> flush privileges;
The GRANT command no longer automatically creates users.
Do not change the NO_AUTO_CREATE_USER
variable, instead first create the user using the CREATE USER
command, then grant the privileges:
DROP USER IF EXISTS 'user'@'localhost';
CREATE USER 'user'@'localhost' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON database_name.* TO 'user'@'localhost';