数据库远程连接失败
mysql远程链接报错
报错信息为:
Host:xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server
出现这种情况的原因是因为:
mysql数据库只允许自身所在的本机器连接,不允许远程连接。
解决:
在mysql所在服务器上面登录进mysql数据库中:
mysql -u root -p
进入到mysql数据库中:
use mysql;
select host from user where user='root';
-- 示例
mysql> use mysql;
Database changed
mysql> select host from user where user='root';
+-----------+
| host |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)
可以看到 我们执行查询语句得到的数据结果中 host 的值是 localhost
我们执行update语句把权限进行修改
然后 刷新配置
update user set host = '%' where user ='root';
flush privileges;
-- 示例
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> select host from user where user='root';
+------+
| host |
+------+
| % |
+------+
1 row in set (0.00 sec)