远程连接mysql8.0时报错:1130, "Host '*.*.*.*' is not allowed to connect to this MySQL server

原因:由于mysql默认只能在本机进行操作,可以更改mysql数据库的user表的host字段即可

mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.07 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host, user from user
    -> ;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
+-----------+------------------+

使用root用户连接时,host用通配符%表示所有ip都可以连接到此mysql服务,本人是在测试环境,所以用通配符,注意生成环境需要指定哪些设备ip可以远程mysql服务器

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

使用上述命令使之生效,完美解决

posted @ 2025-11-09 12:25  YouThIU  阅读(28)  评论(0)    收藏  举报