使用mysql数据库时,遇到如下错误:

ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘mysql’

这是由于mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的”@’localhost’可以看出来。

具体解决步骤如下:

1.关闭mysql

# service mysqld stop

2.屏蔽权限

# mysqld_safe --skip-grant-table
 or 
# /usr/bin/mysqld_safe --skip-grant-table
Starting demo from .....

3.新开起一个终端输入

# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';//重置root密码

mysql> delete from user where USER='';//删除空用户

mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
mysql> exit

4.重启mysql

# service mysqld restart

其他问题

问题1:
对于mysql 5.7,使用时可能遇到:

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

要求重置密码,但重置root密码时:

“the unknown field Password error above use”

则使用:

mysql>set authentication_string=password('my_password') where user='root';

或者

mysql> set password=password('new_password');

问题2:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

提示密码复杂度不够,密码要包括数字,大小写,特殊符号等

mysql> set password=password('!XXXXX);
Query OK, 0 rows affected, 1 warning (0.00 sec)

参考:

http://www.cnblogs.com/Anker/p/3551610.html

http://myway84.iteye.com/blog/1001915

https://superuser.com/questions/603026/mysql-how-to-fix-access-denied-for-user-rootlocalhost

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐