MySQl只能本地登入,無法遠端登入
阿新 • • 發佈:2019-01-27
環境:
Ubuntu
Mysql 5.7.20
判斷Mysql的埠狀態
netstat -apn |grep 3306
如果輸出結果包括tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
時,說明監聽的host為127.0.0.1
,只能本地訪問,需要設定監聽host:
- 需要修改監聽的host
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
註釋掉bind-address = 127.0.0.1
, 即#bind-address = 127.0.0.1
- 重啟服務
sudo /etc/init.d/mysql restart
- 檢視埠狀態
netstat -apn |grep 3306
此時應為:tcp6 0 0 :::3306 :::* LISTEN -
修改使用者表
當遠端訪問出現not allowed
的提示訊息時,說明遠端使用者無許可權,則需要修改使用者表:
1. 登入資料庫
mysql -u root -p
2. 選擇資料庫
use mysql;
3. 修改root使用者可以在所有機器登入(root只是舉例,%表示所有機器)
update user set host = '%' where user = 'root';
4. 重啟服務
sudo /etc/init.d/mysql restart