简体   繁体   English

如何连接到其他主机上的MySQL守护进程?

[英]How can I connect to a MySQL deamon on other host?

I'd like to connect to MySQL (deamon is running on my VPS) via HeidiSQL. 我想通过HeidiSQL连接到MySQL(deamon在我的VPS上运行)。 I've created new user, commented bind-adress option and when I try to connect with it via HeidiSQL, I've got an error 2003: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10061). 我创建了新用户,并注释了bind-adress选项,当我尝试通过HeidiSQL与之连接时,出现错误2003:无法连接到“ xxx.xxx.xxx.xxx”上的MySQL服务器(10061 )。 What should I do? 我该怎么办?

It could be a number of factors. 这可能是许多因素。

See if a firewall is blocking your traffic to the other host 查看防火墙是否阻止您访问另一主机

Can you simply ping the host from the client machine? 您可以简单地从客户端计算机ping主机吗?

Can you also open a simple telnet session to the host on port 3306 ? 您还能在端口3306上打开到主机的简单telnet会话吗? (If the telnet is accepted, you will probably see some characters appear and you will remain in the telnet session for a few seconds before the connection is closed. If not accepted, you will see the message Connection refused.) (如果接受telnet,您可能会看到一些字符出现,并且在关闭连接之前您将在telnet会话中停留几秒钟。如果不接受,您将看到消息Connection拒绝。)

There's a simple checklist for this: 有一个简单的清单:

  • Is your MySQL server bound to "localhost" only? 您的MySQL服务器是否仅绑定到“ localhost”? It might be listening for connections only on 127.0.0.1 or ::1 instead of any which is usually 0.0.0.0. 它可能仅在127.0.0.1或:: 1上侦听连接,而不是通常在0.0.0.0上的侦听。 Try connecting on your server to your server with mysql --host=host_ip where host_ip is your network IP address. 尝试使用mysql --host=host_ip将服务器连接到服务器,其中host_ip是您的网络IP地址。 I think the default is localhost-only. 我认为默认值为仅本地主机。
  • Is port 3306 firewalled? 端口3306是否已防火墙? Many distributions allow only SSH by default, so you may need to open this up to your client machine. 默认情况下,许多发行版仅允许SSH,因此您可能需要在客户端计算机上打开它。 Try not to open this up to everyone on the internet as having an open MySQL port is asking for trouble. 尽量不要向互联网上的所有人开放此功能,因为拥有开放的MySQL端口会带来麻烦。 It's always best to limit access to a set of specific IPs if possible. 如果可能的话,最好始终限制对一组特定IP的访问。
  • Can you connect via an SSH tunnel instead? 您可以改为通过SSH隧道连接吗? This is far more secure as it means your 3306 port is properly firewalled. 这更加安全,因为这意味着您的3306端口已正确进行了防火墙保护。 There are many tools for creating SSH tunnels, but the basic principle is to forward a local port of your choosing to the remote server's port 3306. 创建SSH隧道的工具很多,但是基本原理是将您选择的本地端口转发到远程服务器的端口3306。

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

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