局域网内连接mysql

2023-11-06  本文已影响0人  FM_0138

安装好mysql后, 如果使用局域网内的其他机器访问mysql, 会报错误:Host is not allowed to connect to this MySQL server
这个错误,其实就是我们安装的MySQL不允许远程登录,解决方法如下:

1, 在装有MySQL的机器上登录MySQL mysql -u root -p, 输入密码,执行如下命令:

use mysql;
 
select host from user where user = 'root';

结果如下: 该结果表示是当前的root用户限制在当前的ip内访问的

mysql> use mysql;
Database changed
mysql> select host from user where user = 'root';
+-----------+
| host      |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)

2, 修改他的访问域

update user set host = '%' where user = 'root';
 
select host from user where user = 'root';

结果如下


mysql> update user set host = ‘%’ where user = ‘root’;
ERROR 1054 (42S22): Unknown column '‘root’' in 'where clause'
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host from user where user = 'root';
+------+
| host |
+------+
| %    |
+------+
1 row in set (0.00 sec)

3.执行 FLUSH PRIVILEGES 或者重启 MySQL 即可;

flush privileges;
上一篇下一篇

猜你喜欢

热点阅读