解决方案 如下:

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

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

 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:\lll\Software\mysql-5.7.30-winx64\bin>net stop mysql
D:\lll\Software\mysql-5.7.30-winx64\bin>net start mysql
mysql -uroot -p

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

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

 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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2022-01-14
  • 2021-08-04
相关资源
相似解决方案