user1432980 user1432980 - 12 days ago 8
MySQL Question

Can't find any matching row in the user table

I am trying to execute this queries -

DROP DATABASE IF EXISTS `hotel`;

GRANT USAGE ON *.* TO 'user'@'localhost';
DROP USER 'user'@'localhost';

CREATE USER user@localhost IDENTIFIED BY 'user';

CREATE DATABASE `hotel`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';

GRANT USAGE ON *.* to 'user'@'localhost' identified by 'user';


But I always get error on

GRANT USAGE ON *.* TO 'user'@'localhost' Error Code: 1133. Can't find any matching row in the user table 0.000 sec


I thought that
Grant usage
create new user if user does not exist. What is wrong?

Answer

I thought that Grant usage create new user if user does not exist. What is wrong?

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.

Comments