ERROR 1396 (HY000): Operation CREATE USER failed for 'username'@'localhost' IDENTIFIED BY 'mypassword';

后端 未结 3 1712
日久生厌
日久生厌 2020-12-16 15:35

Mistakenly I deleted my root user from my mysql.user table.

delete from mysql.user where user=\'username\';

To make same root

相关标签:
3条回答
  • 2020-12-16 16:10

    If you use DROP USER command to remove the user, then the user gets removed completely. If you have to add user with same username later, you can use FLUSH PRIVILEGES command to completely remove privileges from the mysql memory.

    DROP USER username@hostname;
    

    You have to restart mysql or run FLUSH PRIVILEGES before creating the same user because there are issues with privileges. To restart mysql in linux based systems

    sudo service mysql restart
    

    to restart in windows systems

    net stop mysql
    net start mysql
    

    To flush privilege in mysql prompt

    FLUSH PRIVILEGES;
    

    You can alternatively use REVOKE command if you know which privileges that the user has

    REVOKE privillege1, privillege2, ... FROM deleted_user@host
    
    0 讨论(0)
  • 2020-12-16 16:15

    As for the above, password field does not exist in my case and mysql throws an error.

    This command helped:

    INSERT INTO mysql.user (user, host, ssl_cipher, x509_issuer, x509_subject, plugin, authentication_string) VALUES ('user', 'localhost', '', '', '', 'mysql_native_password', PASSWORD('pass'));
    
    0 讨论(0)
  • 2020-12-16 16:34

    This user must be referenced in other tables from the mysql system schema. I would recreate the user the same way you deleted it:

    INSERT INTO mysql.user (user, host, password)
    VALUES ('root', 'localhost', PASSWORD('pasw'));
    

    Then

    FLUSH PRIVILEGES;
    GRANT ALL ON *.* TO 'root'@'localhost';
    

    Yet another reason to never mess with this schema (sorry, I couldn't help).

    0 讨论(0)
提交回复
热议问题