MySQL:1130 Host ‘localhost‘ is not allowed to connect to this MySQL server

开发中突然遇到本地不能登录MySQL,提示1130 Host 'localhost' is not allowed to connect to this MySQL server 或 1130 Host '::1' is not allowed to connect to this MySQL server

解决方法:

首先在mysql的安装目录下找到 my.ini文件,之后用记事本打开,找到[mysqld] 这一行,在它的下面加入两条语句

skip-name-resolve

skip-grant-tables

然后保存,退出。在cmd里重启MySQL服务,即先 net stop mysql,然后net start mysql

接着cmd进入mysql安装目录的bin文件夹,使用mysql -u root -p 进入mysql,密码直接跳过即可

接着执行命令: grant all privileges on *.* to root@'localhost' identified by '123456';(允许root用户从本地local host连接到mysql,并以123456作为密码)

如果提示

则执行:flush privileges;

如果该命令不能执行,可以执行多次,直到返回一下结果

然后再次执行:grant all privileges on *.* to root@'localhost' identified by '123456';

最后退出mysql,回到my.ini文件,删除 skip-name-resolve 和skip-grant-tables ,重新启动mysql服务

猜你喜欢

转载自blog.csdn.net/weixin_38676276/article/details/107446623
今日推荐