Mysql – 解决Access denied for user ”@’localhost’ to database ‘mysql’问题
问题的引出:我在CentOS上装完mysql后,用navicat链接的时候,抛出
MySql - SQL Error (1130): Host IP is not allowed to connect to this MySQL server
错误,具体解决方法请参考本人日志http://361324767.blog.163.com/blog/static/114902525201232832621498/。
该问题解决后,本人登录mysql ,输mysql -u root时无错,但是执行如下语句时:
mysql> use mysql
抛出该错误,参考网上各位大抄的大作如下:
---------------------------------------------------------------------------------------------------------
如先输入mysql,成功启动后输入use mysql,出现如下错误:
Access denied for user ''@'localhost' to database 'mysql'
还有,输mysql可以,输mysql -u root就出错了:
Access denied for user 'root'@'localhost' (using password: NO).
The reason is:
是昨日更新ROOT密码时出错
update user set password = '123456' where user ="root" //这样写是错的,密码其实不是123456
应该为update user set password = password ('123456') where user = "root"
具体操作步骤:
关闭mysql:
# service mysqld stop
然后:
# mysqld_safe --skip-grant-tables
启动mysql:
# service mysqld start mysql -u root mysql> use mysql mysql> UPDATE user SET Password=PASSWORD('xxx') WHERE user='root'; mysql> flush privileges; mysql>\q
-----------------------------------------------------------------------------------------------------------
按照各位大抄的步骤一步一步做,没有任何效果,仔细研究错误信息中的 user''@'localhost' ,说明user表中的user=‘’的信息有误,然后执行
UPDATE user SET Password=PASSWORD('') WHERE user='';
果断没有作用。
最后不允许匿名登录,执行以下语句
mysql> delete from user where user=''; mysql > flush privileges; mysql> \q # service mysqld restart
问题解决。
源:http://361324767.blog.163.com/blog/static/11490252520124454042468/