Access denied for user \'root\'@\'localhost\'”解决办法

遇到Access denied for user 'root'@'localhost'”这种报错,可以采用重新设置密码解决,方法如下:

方法一:

# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>

方法二:

1.关闭服务
2.修改/etc/my.cnf文件:
具体内容:[mysqld] 加上skip-grant-tables,保存
3.重启服务
4.登陆mysql,并修改密码
mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
5.修改完毕后,退出,并关掉服务
6.将skip-grant-tables从配置中去除
7.启动服务mysqld即可

你可能感兴趣的:(Access denied for user \'root\'@\'localhost\'”解决办法)