Can't find any matching row in the user table

前端 未结 5 629
攒了一身酷
攒了一身酷 2020-12-08 07:00

I am trying to execute this queries -

DROP DATABASE IF EXISTS `hotel`;

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

CRE         


        
相关标签:
5条回答
  • 2020-12-08 07:13

    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.

    0 讨论(0)
  • 2020-12-08 07:17

    Try to add to the end of the script:

    FLUSH PRIVILEGES;
    
    0 讨论(0)
  • 2020-12-08 07:27

    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';
    
    0 讨论(0)
  • 2020-12-08 07:34

    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;
    
    0 讨论(0)
  • 2020-12-08 07:36

    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';
    
    0 讨论(0)
提交回复
热议问题