免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1352 | 回复: 0
打印 上一主题 下一主题

Access denied for user \'root\'@\'localhost\' [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-22 08:53 |只看该作者 |倒序浏览
    今天Red Hat Enterprise Linux 6.0上跑得mysql神不知鬼不觉地执行mysql -u root -p登录时,报出了错误:Access denied for user 'root'@'localhost' (using password: YES),但服务器每有做任何的改动,昨天还跑得好好的,也不晓得什么原因。在网上查找了下原因,找到一篇文章提供了如下的解决方法:
# /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>

mysql>
    说明:执行第二个命令后,一直会停留不会退出,手动敲下回车键即可。
    这个方法实际就是更改root的密码,只是我按部就班的敲了上面的命令,仍然报错误:Access denied for user 'root'@'localhost' (using password: YES).
    后来查找了好久,才发现这篇文章的方法少了一点点,在我的机器环境是少了一个命令,可能具体的实际环境不一样吧。
    最终自己的解决方法如下:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> grant all on *.* to 'root'@'localhost' identified by '123456';
mysql> FLUSH PRIVILEGES;

mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>

mysql>
这样就可以了,增加了红色的两句代码。
   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP