2017-02-27 64 views
4

我試圖從我的工作站連接到安裝在Ubuntu 16.04上的遠程MySQL服務器5.7。無法連接到數字海洋中的遠程MySQL服務器

這是我得到的錯誤(使用Navicat連接)。

enter image description here

爲了使它工作,我跟着下面的步驟。

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.cnfmy.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.0my.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]:~$ 

回答

0

有關添加bind-address=0.0.0.0到/etc/mysql/my.cnf,一定要實際添加2行:

的[mysqld]

綁定地址= 0.0.0.0

這將解決您的「更新」段落中的錯誤,並希望整個場景將起作用。

1

使用以下方法來調試這 -

首先,你需要在/ var瞭解什麼日誌在Ubuntu says-默認的日誌是存儲/日誌/ MySQL的文件夾或去提到的位置在/etc/mysql/my.cnf

其次,如果你想從任何地方訪問你的mysql服務器,那麼只需在#開頭註釋該行。所以,請讓位於bind-address行。它現在將從任何地方訪問。

[mysqld] 
# bind-address=0.0.0.0 

啓動MySQL服務器,並使用來自客戶端系統的telnet與IP &端口。檢查是否可以連接或不連接。爲前

telnet xx.xx.xx.xx 3306 

如果能夠進行連接,然後在MySQL服務器,在那裏我的主機名,這意味着它可以從任何客戶端連接爲前

GRANT ALL ON database_name.* TO 'user'@'%' IDENTIFIED BY 'your_password'; 

如果仍然使用%創建用戶它顯示錯誤,那麼你需要發佈日誌。