遇到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文件:
具體內(nèi)容:[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即可