關於遠端連線MySQL資料庫的問題解決,mysql資料庫

來源:互聯網
上載者:User

關於遠端連線MySQL資料庫的問題解決,mysql資料庫
問題描述

出於興趣,本人在Windows和Ubuntu系統上均安裝了MySQL伺服器和用戶端。現在有這樣一些預備資訊:

  • Windows系統的IP地址: 192.168.5.196
  • Ubuntu系統的IP地址:192.168.5.228

現在我試圖在Windows上遠端連線Ubuntu終端主機。
首先,在遠程Ubuntu主機上配置MySQL存取權限,具體過程如下:

mysql> grant all privileges on . to ‘longlong’@’%’ identified by ‘123456’;

現在,在Ubuntu主機上查詢MySQL許可權資訊如下:

現在,在Windows上遠程登入Ubuntu主機MySQL資料庫,結果為:


一直報出這種錯誤!

問題解決方案

在CSDN ASK提出這個問題後,嘗試了各位麼麼噠網友的建議,比如通過mysql -u xx -p xxxx -h xxxx或是關閉Windows防火牆以及通過 ufw disable 命令關閉Ubuntu防火牆,仍然無法解決這個問題。
後來,得知Ubuntu上MySQL通過/etc/mysql/my.cnf設定檔配置整個MySQL。摘錄一二:

[mysqld]
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp

Instead of skip-networking the default is now to listen only on localhost which is more compatible and is not less secure.

bind-address = 127.0.0.1

注意,在上述設定檔中,存在一句配置命令:

bind-address = 127.0.0.1

這句命令即表明,本Ubuntu主機在本地監聽,僅處理本地的串連請求。
我們也可以通過netstat命令來查看相關連接埠監聽資訊:

shell> netstat -anp | grep 3306
output> tcp 127.0.0.1:3306 LISTEN

現在,我們將my.cnf的bind-address語句注釋掉,並重啟MySQL服務:

shell> sudo service mysql restart
output> mysql stop/waiting mysql start/running, process 25765

現在,我們在Windows遠端連線Ubuntu上的MySQL資料庫,就不會報錯了。
再次運行netstat命令:

shell> netstat -anp | grep 3306
output> tcp 0.0.0.0:3306 LISTEN

這時,我們發現3306連接埠不再僅僅監聽在本地,同時也可以監聽來自遠端的串連請求。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.