新裝的 MySQL 不容許遠程鏈接

新裝的 MySQL 一般會出現這樣的狀況:沒法遠程鏈接,可是本地鏈接是正常的.mysql

問題緣由

新裝的 MySQL 一般默認的用戶是 root, 而爲了安全起見, root 用戶是不容許遠程鏈接.sql

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.04 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user, host from user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| mysql.sys | localhost |
| root      | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)

解決辦法

  1. 暴力修改(不安全,不合理,不建議,也就不介紹了)
  2. 新增一個對應權限的用戶,並啓用遠程鏈接(安全、可靠、無污染).
# 新增用戶及密碼,並授予對應的權限
grant all privileges on yourDatabase.* to "yourUser"@"%" identified by "yourPassword";
# 刷新權限
flush privileges;
相關文章
相關標籤/搜索