且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL无法连接到远程服务器

更新时间:2022-05-18 08:28:41

确实这可能是一个很大的可能原因,希望这是一个开始:

Really this could be a magnitude of possible reasons, hopefully this is a start:

检查基本网络

从MySQL虚拟机打开命令提示符,然后键入IPCONFIG /ALL.这将显示绑定到不同网络适配器的所有IP地址.

From the MySQL virtual machine open up a command prompt and type IPCONFIG /ALL. This will show you all the IP addresses bound to different network adapters.

检查您所连接的IP地址是否在此处列出,虚拟机重启后可能已从DHCP获得了新IP,而不是具有静态IP.

Check that the IP address you're connected to is listed there, the virtual machine might have got a new IP from DHCP rather than having a static IP after its restart.

主机名与IP

您应该检查主机名解析,从引述的错误中可以看出您正在连接的是主机名而不是服务器IP.检查您的计算机可以使用正确的IP地址解析为主机名-在连接字符串中更改服务器实际IP的主机名也很值得.

You should check the hostname resolution, from your quoted error it would suggest you are you are connecting to a hostname rather than a server IP. Check your machine can resolve to the hostname using the correct IP address - it could also be worth changing the hostname for the actual IP of the server in the connection string.

MySQL配置文件

您已经说过您正在Windows上运行MySQL,习惯上是将my.cnf重命名为my.ini. 4.1.5之前版本的MySQL较早版本的配置文件通常存储在c:\my.inic:\windows\my.ini中.对于此后的版本,默认位置通常是安装目录%PROGRAMDATA%\MySQL\MySQL Server xxx.

You've said you're running MySQL on Windows, it was customary to rename the my.cnf to my.ini. The configuration file for older versions of MySQL previous to 4.1.5 was usually stored in either c:\my.ini or c:\windows\my.ini. For versions after this the default location is the installation directory usually %PROGRAMDATA%\MySQL\MySQL Server xxx.

找到配置文件后,请在记事本(或类似的文本编辑器)上将其打开,找到[mysqld]部分,并确保port=您要连接的端口和bind-address= IP您尝试连接的地址.

When you have located the configuration file please open it on Notepad (or similar text editor), locate the [mysqld] section and make sure that port= the port you're trying to connect to and bind-address= the IP address you're trying to connect to.

服务器端口

在MySQL虚拟服务器上,打开命令提示符并键入netstat –ano,这将向您显示进程列表以及它们正在侦听的IP/端口. MySQL服务器应在此处列出,并且应在配置文件所定义的端口和IP上进行监听.

From the MySQL virtual server open a command prompt and type netstat –ano, this will show you a list of processes and what IP's / ports they are listening on. The MySQL server should be listed here and should be listening on the same port and IP as the config file defines.

Windows防火墙

您应该具有允许MySQL的防火墙规则,以下内容将在默认端口3306上添加一个

You should have a firewall rule to allow MySQL, the following will add one on the default port of 3306

netsh advfirewall firewall add rule name="MySQL Server" action=allow protocol=TCP dir=in localport=3306

确定这是否是特定于机器的

您可以在另一个工作站上安装MySQL Workbench应用程序,然后尝试连接以识别这是全局问题还是仅仅是与您的特定工作站相关的一个问题.

You could setup the MySQL Workbench application on another workstation and try to connect to identify if this is a global problem or just one related to your specific workstation.