mysql error 1130 hy000:Host 'localhost' is not allowed to connect to this mysql server

解决方案 如下:

1、在安装mysql的根目录下新建一个文件:my.ini(如果有的话,就不用新建了)

 2、编辑my.ini文件

[mysql]
 
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
#设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir=D:\softnew\MYSQL\mysql-5.7.20-winx64
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
skip-grant-tables 

注意:mysql的安装目录要换成自己的mysql安装目录。

如果已经有my.ini文件在文件末尾添加

skip-grant-tables 

3、重新启动mysql,并登陆mysql

D:lllSoftwaremysql-5.7.30-winx64in>net stop mysql
D:lllSoftwaremysql-5.7.30-winx64in>net start mysql
mysql -uroot -p

此时不需要输入密码,直接回车即可

 

 4、grant授权

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

如果此处报错  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服务。

最后:如果设置过程中提示没有权限,请使用管理员权限打开cmd

参考文档:

https://blog.csdn.net/piaoxuan1987/article/details/79282604

https://blog.csdn.net/baidu_41909653/article/details/82148455

原文地址:https://www.cnblogs.com/minmin123/p/13554551.html