mysql初次使用出现Access denied for user ‘root‘@‘localhost‘问题解决方法----可用

今天是要rancher部署了mysql,但是后来启用的时候发现mysql无法登录,出现Access denied for user 'root'@'localhost' 

的问题。之前在安装mysql的时候遇到过这个问题,没有进行记录,现在把这个坑记录一下,与大家分享

1、编辑 /etc/my.cnf or /etc/mysql/my.cnf

2、/etc/my.cnf文件中添加skip-grant-tables。

3、重启mysql

4、重新登录mysql

5、flush privileges;

6、设置新的密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';

7、/etc/my.cnf文件中去掉skip-grant-tables。

8、重启mysql

  1. Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
  2. Add skip-grant-tables under [mysqld]
  3. Restart Mysql
  4. You should be able to login to mysql now using the below command mysql -u root -p
  5. Run mysql> flush privileges;
  6. Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
  7. Go back to /etc/my.cnf and remove/comment skip-grant-tables
  8. Restart Mysql
  9. Now you will be able to login with the new password mysql -u root -p

猜你喜欢

转载自blog.csdn.net/qq_29235677/article/details/120690613