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)