无法连接到Digital Ocean中的远程MySQL服务器

Cod*_*ody 5 mysql

我正在尝试从我的工作站连接到安装在Ubuntu 16.04上的远程MySQL服务器5.7.

这是我得到的错误(使用Navicat连接).

在此输入图像描述

为了使其工作,我按照以下步骤.

1)GRANT ALL ON database_name.* TO user@xx.xxx.xx.xx IDENTIFIED BY 'your_password';

2) flush privileges;

3) sudo /etc/init.d/mysql restart

有些论坛建议评论线与"绑定地址"开始my.cnf驻留在/etc/mysql/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/
Run Code Online (Sandbox Code Playgroud)

我还尝试使用以下命令在防火墙上打开端口.

sudo ufw allow 3306/tcp
sudo service ufw restart
Run Code Online (Sandbox Code Playgroud)

但仍然坚持同样的问题.

更新:让MySQL收听我添加bind-address=0.0.0.0my.cnf文件的所有接口 .现在MySQL甚至没有重启并抛出以下错误.

demo@ubuntu:~$ 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!
demo@ubuntu:~$
Run Code Online (Sandbox Code Playgroud)

Bob*_*ait 0

关于添加bind-address=0.0.0.0到 /etc/mysql/my.cnf,请确保您实际添加了 2 行:

[mysqld]

绑定地址=0.0.0.0

这将解决“更新”段落中的错误,并希望整个方案能够发挥作用。