我試圖從我的工作站連接到安裝在Ubuntu 16.04上的遠程MySQL服務器5.7。無法連接到數字海洋中的遠程MySQL服務器
這是我得到的錯誤(使用Navicat連接)。
爲了使它工作,我跟着下面的步驟。
1)GRANT ALL ON database_name.* TO [email protected] IDENTIFIED BY 'your_password'
;
2)flush privileges;
3)sudo /etc/init.d/mysql restart
有些論壇建議註釋符合駐留在/etc/mysql/my.cnf
上my.cnf
「綁定地址」 開始。問題是我的安裝中沒有這樣的行。
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
我也嘗試使用以下命令在防火牆上打開端口。
sudo ufw allow 3306/tcp
sudo service ufw restart
但仍然存在同樣的問題。
更新:爲了使MySQL聆聽到所有的接口,我增加 bind-address=0.0.0.0
到my.cnf
文件。現在MySQL甚至不重新啓動並引發以下錯誤。
[email protected]:~$ sudo /etc/init.d/mysql restart
[....] Restarting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
failed!
[email protected]:~$