MySQL on Ubuntu (Linux) 開啟遠端連線

將運行於 Ubuntu 的 MySQL 開啟遠端連線,達到跨平台使用的目的,由於 MySQL 與 Ubuntu (Linux) 各自版本眾多,環境兼容上會出現很多的問題,因此需先將 Ubuntu (Linux) 的版本與 MySQL 的版本確認好在進行環境的設定。

項目版本
Ubuntu(Linux)20.04.2.0
MySQL Community Server8.0.27
Oracle VirtualBox6.1.14 r140239 (Qt5.6.2)

先以 root 最高權限登入 MySQL

mysql -u root -p

新增帳號 Sam 
remote_server_ip : 遠端要連入的電腦ip
password : 密碼

CREATE USER 'sam'@'remote_server_ip' IDENTIFIED WITH mysql_native_password BY 'password';

確認新增結果

select host,user from user;

重整權限

flush privileges;

於 windows 上 MySQL Workbench 連線 …. 失敗

使用Telnet 測試 MySQL port 狀態

 telnet 192.168.X.X 3306

取得錯誤訊息 : E Host '192.168.X.X' is not allowed to connect to this MySQL server
推測 port 與 MySQL 還未開啟遠端連線

設定 /etc/mysql/mysql.conf.d/mysqld.cnf 
將 bind-address = 127.0.0.1 改為 bind-address = 0.0.0.0

. . .
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0
. . .

修改帳號Sam

update user set host = '%' where user='sam' and host = '10.0.2.15';

確認修改結果

select host,user from user;

重整權限

flush privileges;

於 windows 上 MySQL Workbench 連線成功!!

參考資料 : 
https://www.digitalocean.com/community/tutorials/how-to-allow-remote-access-to-mysql
https://www.itread01.com/content/1546804635.html