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

來源:互聯網
上載者:User

標籤:配置   系統   

問題描述

出於興趣,本人在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]
38 port = 3306
39 basedir = /usr
40 datadir = /var/lib/mysql
41 tmpdir = /tmp
45 # Instead of skip-networking the default is now to listen only
46 # on localhost which is more compatible and is not less secure.
47 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連接埠不再僅僅監聽在本地,同時也可以監聽來自遠端的串連請求。

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.