尝试连接到远程 MySQL 主机(错误 2003)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5713808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:34:02  来源:igfitidea点击:

Trying to connect to remote MySQL host (error 2003)

mysqldebianiptablesmysql-error-2003

提问by hellsgate

I have a MySQL instance running on a Debian server and I can connect to it locally with no problems. However, I am unable to connect to it remotely. When I try this from my command line I get the following error:

我有一个在 Debian 服务器上运行的 MySQL 实例,我可以毫无问题地在本地连接到它。但是,我无法远程连接到它。当我从命令行尝试此操作时,出现以下错误:

ERROR 2003 (HY000): Can't connect to MySQL server on '<server-ip>' (110)

I've added the user to mysql as 'user'@'*' and 'user'@'localhost'. skip-networking in this server is set to false and the bind-address is commented out in my.cnf. I've also attempted to open port 3306 in iptables using the following command:

我已将用户作为 'user'@'*' 和 'user'@'localhost' 添加到 mysql。此服务器中的skip-networking 设置为false,并且在my.cnf 中注释掉了绑定地址。我还尝试使用以下命令在 iptables 中打开端口 3306:

/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT

Here is a listing of all my iptable firewall rules, which I retreived using iptables -L:

这是我使用 iptables -L 检索的所有 iptable 防火墙规则的列表:

Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
REJECT     tcp  --  anywhere             anywhere            tcp dpt:auth reject-with icmp-port-unreachable 
ACCEPT     icmp --  anywhere             anywhere            icmp type 8 code 0 state NEW,RELATED,ESTABLISHED,UNTRACKED 
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     tcp  --  anywhere             anywhere            tcp spts:1024:65535 dpt:ftp state NEW 
ACCEPT     tcp  --  anywhere             anywhere            tcp spts:1024:65535 dpt:ssh state NEW 
ACCEPT     tcp  --  anywhere             anywhere            tcp spts:1024:65535 dpt:www state NEW 
ACCEPT     tcp  --  <my-server>          anywhere            tcp spts:1024:65535 dpt:mysql state NEW 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpts:49152:65534 state NEW 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:mysql 
LOG        all  --  anywhere             anywhere            limit: avg 5/min burst 5 LOG level debug prefix `iptables denied: ' 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:mysql 
LOG        tcp  --  anywhere             anywhere            tcp dpt:mysql LOG level debug 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Does anyone have any idea where I should go from here?

有谁知道我应该从这里去哪里?

采纳答案by Mike Pennington

Based on your response, you need to find if there is a device between you and the server that blocks your connection. You should also ensure that you can telnet to 3306 on that server's ethernet address when logged into the server... if not, you probably have not got the service bound to the ethernet in my.cnf... see the bind-addressparameter.

根据您的响应,您需要查找您和服务器之间是否存在阻止您连接的设备。您还应该确保在登录服务器时可以在该服务器的以太网地址上 telnet 到 3306 ...如果没有,您可能还没有将服务绑定到以太网my.cnf...请参阅bind-address参数。

回答by anony

You should check your MySQL Server configuration to see if it bind to 127.0.0.1, then you can only connect to mysql if your app is on same server. There's an easy way, to have webamin installed and you can control via web interface.

您应该检查您的 MySQL 服务器配置以查看它是否绑定到 127.0.0.1,然后如果您的应用程序在同一台服务器上,您只能连接到 mysql。有一个简单的方法,安装 webamin,您可以通过 Web 界面进行控制。

回答by Basil Jose

This may due to 3306 port is closed , check your server port status

这可能是由于 3306 端口被关闭,请检查您的服务器端口状态

http://www.yougetsignal.com/tools/open-ports/

http://www.yougetsignal.com/tools/open-ports/

If it shows closed, that means you can't access it from out side the machine , to open the port

如果显示已关闭,则表示您无法从机器外部访问它以打开端口

ufw - Uncomplicated Firewall

ufw - 简单的防火墙

The default firewall configuration tool for Ubuntu is ufw. The following are some examples of how to use ufw:

Ubuntu 的默认防火墙配置工具是 ufw。以下是如何使用 ufw 的一些示例:

First, ufw needs to be enabled. From a terminal prompt enter:

首先,需要启用 ufw。从终端提示输入:

sudo ufw enable

To open a port (mysql):

打开一个端口(mysql):

sudo ufw allow 3306

To see the firewall status, enter:

要查看防火墙状态,请输入:

sudo ufw status

回答by Amit Contractor

If you use VPN connection to connect remote database server and you got this kind of error then just check it out two simple steps...

如果您使用 VPN 连接连接远程数据库服务器并且出现此类错误,那么只需检查两个简单的步骤...

1) In windows machine, please go to "Control Panel\Network and Internet\Network Connections" path and right click on local area network and go to properties. Click on TCP/IPv4 and go the properties. Make sure the IP and DNS server(if you use DHCP or not?).

1) 在 windows 机器中,请进入“控制面板\网络和 Internet\网络连接”路径并右键单击局域网并转到属性。单击 TCP/IPv4 并转到属性。确保 IP 和 DNS 服务器(是否使用 DHCP?)。

2) After this please restart the Machine and check it out again.

2) 在此之后,请重新启动机器并再次检查。

Hope this will work. In my case it works.

希望这会奏效。就我而言,它有效。

Note: Please make sure all your settings are correct. This answer is funny but it works in my case :)

注意:请确保您的所有设置都正确。这个答案很有趣,但它适用于我的情况:)

Thanks!

谢谢!

回答by Nasir Mahmood

for me this was to enable the port 3306 in /etc/default/iptablesfile to allow the incoming traffic from any host by uncommenting the below given line:

对我来说,这是/etc/default/iptables通过取消注释以下给定行来启用文件中的端口 3306以允许来自任何主机的传入流量:

#-A INPUT -p tcp --dport 3306 -j ACCEPT