在Ubuntu上部署mysql服務並添加了一個非root用戶後,發現沒法遠程鏈接,html
Navicat鏈接mysql出現2003——can't connect to mysql server on localhost(10061)。mysql
在網上搜索了一圈後,幾乎都指向一個解決方案:修改配置文件/etc/mysql/my.cnf中的一項配置:sql
bind-address = 127.0.0.1
改成:ubuntu
bind-address = 0.0.0.0
雖然你們都這麼說,可是沒有說明緣由,因而我又找了一番,終於找到了,特轉載於此,vim
原文在這裏,感謝原做者。服務器
========== 如下爲轉載 ==========tcp
服務監聽在127.0.0.1和0.0.0.0上,到底有什麼區別呢?給個實際的例子,你們看看ide
今天發如今nb1380的mysql從nb1381連不上? oop
一、使用grant加權限,失敗spa
二、telnet失敗,考慮多是iptables限制,加規則,無效
三、猜想多是監聽在127.0.0.1上,而不是0.0.0.0上,查看my.cnf,果真是這個緣由
總結:
3306端口監聽在127.0.0.1,只有本機客戶端能夠訪問,其餘服務器沒法訪問
3306端口若是監聽在0.0.0.0上,若是沒有端口限制,那麼其餘服務器則能夠鏈接該服務器的該端口
========== 轉載結束 ==========
文章到這裏還沒結束,經過錯誤代碼10061,我查到了官方文檔的說法。鏈接以下:
https://dev.mysql.com/doc/refman/8.0/en/can-not-connect-to-server.html
這裏剪輯部份內容:
The error (2003) Can't connect to MySQL server on '
indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, and that the network port you specified is the one configured on the server.server
' (10061)
Make sure that the server has not been configured to ignore network connections or (if you are attempting to connect remotely) that it has not been configured to listen only locally on its network interfaces. If the server was started with --skip-networking
, it will not accept TCP/IP connections at all. If the server was started with --bind-address=127.0.0.1
, it will listen for TCP/IP connections only locally on the loopback interface and will not accept remote connections.
其實官方文檔已經寫清楚了,之後有問題,找官方文檔結合別人的實踐經驗效率更高。