ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

使用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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值