简体   繁体   English

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

[英]Unable to connect to remote MySQL Server in Digital Ocean

I am trying to connect to a remote MySQL server 5.7 installed on Ubuntu 16.04 from my workstation. 我正在尝试从我的工作站连接到安装在Ubuntu 16.04上的远程MySQL服务器5.7。

Here is the error i am getting (Using Navicat to connect). 这是我得到的错误(使用Navicat连接)。

在此输入图像描述

To make it work I followed the following steps. 为了使其工作,我按照以下步骤。

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

2) flush privileges; 2) flush privileges;

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

Some forums recommends commenting line starts with "bind-address" on my.cnf which resides in /etc/mysql/my.cnf . 有些论坛建议评论符合“绑定地址”上启动my.cnf驻留在/etc/mysql/my.cnf The problem is there is no such line on my installation. 问题是我的安装没有这样的线路。

#
# 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/

I also tried to open ports on firewall using the following commands. 我还尝试使用以下命令在防火墙上打开端口。

sudo ufw allow 3306/tcp
sudo service ufw restart

But still stuck with the same problem. 但仍然坚持同样的问题。

Update: To make MySQL to listen to all interfaces i added bind-address=0.0.0.0 to my.cnf file. 更新:为了使MySQL能够监听所有接口,我将bind-address=0.0.0.0添加到my.cnf文件中。 Now MySQL is not even restarting and throws the following error. 现在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:~$

Use the following ways to debugging this- 使用以下方法调试此 -

First you need to understands what the logs says- the default logs in ubuntu is stores in /var/log/mysql folder or go to mentioned location in /etc/mysql/my.cnf . 首先你需要了解日志的内容 - ubuntu中的默认日志存储在/ var / log / mysql文件夹中,或者转到/etc/mysql/my.cnf提到的位置。

Second if you want to access your mysql server from any where location then just comment the line by putting # at starting. 其次,如果你想从任何位置访问你的mysql服务器,那么只需在开始时输入#来注释该行。 So please conmment the bind-address line. 所以请说明绑定地址行。 It will now access from any where. 它现在可以从任何地方访问。

[mysqld]
# bind-address=0.0.0.0

Start the mysql server and use telnet from client system with the ip & port. 启动mysql服务器并使用ip&port从客户端系统使用telnet。 Check are you able to connect or not. 检查您是否能够连接。 for ex- 为前

telnet xx.xx.xx.xx 3306

If you are able to connect then create user in mysql server, where I used % in hostname which means it can be connect from any client For ex- 如果你能够连接然后在mysql服务器中创建用户,我在主机名中使用%,这意味着它可以从任何客户端连接

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

If still its showing errors then you need to post the logs. 如果仍然显示错误,那么您需要发布日志。

about adding bind-address=0.0.0.0 to /etc/mysql/my.cnf, make sure you actually add 2 lines: 关于将bind-address=0.0.0.0添加到/etc/mysql/my.cnf,请确保实际添加2行:

[mysqld] 的[mysqld]

bind-address=0.0.0.0 绑定地址= 0.0.0.0

This will solve the error in your "Update" paragraph, and hopefully the whole scenario will work. 这将解决“更新”段落中的错误,并希望整个场景都能正常工作。

I had the same problem. 我有同样的问题。 and fixed myself. 并固定自己。

!includedir /etc/mysql/conf.d/

!includedir /etc/mysql/mysql.conf.d/

it means you should check conf.d and mysql.conf.d folder. 这意味着你应该检查conf.d和mysql.conf.d文件夹。 there will be conf files. 会有conf文件。 so, you can change bind-address in the real conf file. 所以,你可以在真正的conf文件中更改bind-address。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM