You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

远程连接MySQL报错ERROR 2003 (HY000)求助,已执行相关配置

Troubleshooting MySQL Remote Connection Error (ERROR 2003)

Hey there, let's work through this remote MySQL connection issue step by step. You've already checked off some key steps, but let's dig into the remaining potential culprits:

1. Verify Firewall Settings on the MySQL Server

The most common reason for this error is a firewall blocking the default MySQL port (3306). Let's confirm and fix this:

  • For Ubuntu/Debian (using ufw):
    • Check current rules: sudo ufw status
    • Allow 3306 traffic: sudo ufw allow 3306/tcp
    • Reload the firewall: sudo ufw reload
  • For CentOS/RHEL (using firewalld):
    • Add the port permanently: sudo firewall-cmd --add-port=3306/tcp --permanent
    • Reload the firewall: sudo firewall-cmd --reload
  • Test tip: Temporarily disable the firewall (sudo ufw disable or sudo systemctl stop firewalld) — if the connection works afterward, the firewall was the issue.

2. Confirm MySQL is Listening on All Interfaces

Sometimes the bind-address change doesn't take effect, or you modified the wrong config file:

  • Check which interfaces MySQL is listening on:
    sudo netstat -tulpn | grep mysql
    # Or use `ss` for newer systems:
    sudo ss -tulpn | grep mysql
    
    You should see a line like 0.0.0.0:3306 or :::3306 (for IPv6). If it still shows 127.0.0.1:
    • Double-check you edited the correct config file — MySQL typically uses files like /etc/mysql/mysql.conf.d/mysqld.cnf or /etc/my.cnf, and the bind-address must be in the [mysqld] section.
    • Verify the MySQL service restarted successfully: sudo systemctl status mysql.service — look for any errors in the output.

3. Validate User Authorization

Let's make sure your grant actually took effect:

  • Log into the local MySQL server and run these queries:
    # Check if the user exists with the correct host
    SELECT user, host FROM mysql.user WHERE user = 'user';
    # Verify granted privileges
    SHOW GRANTS FOR 'user'@'xx.xx.xx.xx';
    
  • If the user isn't listed or privileges are missing, re-run the authorization (note: MySQL 8.0+ requires separate CREATE USER and GRANT commands):
    CREATE USER 'user'@'xx.xx.xx.xx' IDENTIFIED BY 'password';
    GRANT ALL ON databaseName.* TO 'user'@'xx.xx.xx.xx';
    FLUSH PRIVILEGES;
    

4. Test Basic Network Connectivity

Before blaming MySQL, confirm the network path is open from your remote server:

  • Ping the MySQL server IP to check reachability: ping xx.xx.xx.xx
  • Test if port 3306 is accessible:
    telnet xx.xx.xx.xx 3306
    # Or use `nc` if telnet isn't installed:
    nc -zv xx.xx.xx.xx 3306
    

If these commands fail, the issue is at the network level (firewall, routing, or ISP restrictions) rather than MySQL.

5. Check for Restrictive MySQL Configurations

  • Look for skip-networking in your MySQL config file — if present, comment it out (this setting disables all remote connections) and restart the service.
  • For older MySQL versions, ensure you don't have bind-address set multiple times in different config files (the last one takes precedence).

内容的提问来源于stack exchange,提问作者usergs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:15:13