ERROR 1698 (28000): Access denied for user 'root'@'localhost'

后端 未结 17 1823
执笔经年
执笔经年 2020-11-22 10:00

I\'m setting up a new server and keep running into this problem.

When I try to login to the MySQL database with the root user, I get the error:

17条回答
  •  眼角桃花
    2020-11-22 10:33

    I found my solution after hours of research here.

    Stop MySQL

    sudo service mysql stop
    

    Make MySQL service directory.

    sudo mkdir /var/run/mysqld
    

    Give MySQL user permission to write to the service directory.

    sudo chown mysql: /var/run/mysqld
    

    Start MySQL manually, without permission checks or networking.

    sudo mysqld_safe --skip-grant-tables --skip-networking &
    

    Log in without a password.

     mysql -uroot mysql
    

    update password

    UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';
    EXIT;
    

    Turn off MySQL.

    sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
    

    Start the MySQL service normally.

    sudo service mysql start
    

提交回复
热议问题