本地连接远程MySQL服务器mysql5.domain.de遇2003(10061)错误求助
Hey there, let's work through this common MySQL connection issue step by step. Error 10061 means your local machine is getting a "connection refused" response from the remote server, so here's what to check:
Verify firewall/security group settings on the remote server
The most common culprit is that the remote server's firewall (or cloud provider security group, if it's hosted on AWS/Azure/GCP) isn't allowing incoming connections on MySQL's default port 3306. You'll need to:- Ensure the firewall rules explicitly allow your local public IP address to access port 3306.
- If you're testing, you can temporarily open port 3306 to all IPs (not recommended for production!) to confirm this is the issue, then lock it down to your specific IP afterward.
Check if MySQL is listening for external connections
By default, MySQL often only listens on the localhost interface (127.0.0.1), which blocks remote connections. To fix this:- Locate your MySQL configuration file (usually
my.cnfon Linux,my.inion Windows). - Look for the
bind-addressdirective — change its value to0.0.0.0(to allow all remote IPs) or your specific local IP address. - Make sure the
skip-networkingline is commented out (if present), as this disables all remote connections entirely. - Restart the MySQL service to apply changes.
- Locate your MySQL configuration file (usually
Confirm your MySQL user has remote access permissions
Even if the network is open, your userymight only be allowed to connect from localhost. To fix this:- Log into the MySQL server directly (via SSH or local access).
- Run this command to grant access from your local IP:
GRANT ALL PRIVILEGES ON x.* TO 'y'@'your_local_public_ip' IDENTIFIED BY 'pw'; FLUSH PRIVILEGES; - If you need to allow access from any IP (use cautiously for security), replace
your_local_public_ipwith%.
Test basic network connectivity
First, confirm the domain resolves correctly: runping mysql5.domain.dein your terminal — it should return the correct public IP of the remote server.
Then test if the port is reachable:- Use
telnet mysql5.domain.de 3306ornc -zv mysql5.domain.de 3306(if you have netcat installed). If this fails, the issue is definitely network-related, not MySQL configuration.
- Use
Check local network restrictions
Don't forget to rule out your own local firewall or proxy settings. Temporarily disable your local firewall to see if the connection works, or check if any proxy is blocking outgoing traffic to port 3306.
内容的提问来源于stack exchange,提问作者user8413951

