mysql error 1130 hy000:Host 'localhost' is not allowed to connect to this mysql server 解决方案

 

ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server

D:\Wamp\mysql-5.6.21\bin>mysql.exe -uroot -p
Enter password:
ERROR 1130 (HY000): Host 'localhost' is not allowed to connect to this MySQL server

 

此处是root账户没有本地数据库的访问权限,所以无法连接数据库,需要使用grant给root账户授权。

授权之前需要登录到数据库,使用skip-grant-tables参数

skip-grant-tables  顾名思义,数据库启动的时候 跳跃权限表的限制,不用验证密码,直接登录。

 

编辑 my.ini,在[mysqld]的段中加上一句:skip-grant-tables 

[mysqld] 
datadir=/var/lib/mysql 
socket=/var/lib/mysql/mysql.sock 
skip-name-resolve 
skip-grant-tables 

 

临时解决方案,亦可以用于忘记mysql root用户密码时使用,安全性也比较难以保证。

 

然后登陆到root账户,此时不需要输入密码就可以进入,然后grant授权

mysql> grant all privileges on *.* to root@'localhost' identified by "123456";

 

如果此处报错  ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

只需要刷新权限就行,flush privileges;

然后再执行授权命令就行了。

 

最后记得在配置文件中删除 skip-grant-tables  参数,然后重启MySQL服务。

 

转载于:https://www.cnblogs.com/rnckty/p/5577818.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值