The MySQL client cannot establish a connection to the MySQL server at the specified host. This commonly occurs when the server isn't running, firewall rules block the connection, the bind address is misconfigured, or network connectivity is unavailable.
ERROR 2003 (HY000): Can't connect to MySQL server on '[host]' is a network-level error thrown by the MySQL client before any communication with the server takes place. Unlike authentication errors (ERROR 1045) that occur after successful connection, error 2003 indicates the client cannot reach the server at all. This can be caused by the MySQL daemon not running, firewall rules blocking TCP/IP access on port 3306 (or the configured port), DNS resolution failures, incorrect hostname/IP in the connection string, or server configuration preventing network connections (skip-networking option enabled).
Check if the MySQL daemon is active on the target host.
On Linux/macOS:
# Check service status
sudo systemctl status mysql
# or
sudo service mysql status
# If not running, start it
sudo systemctl start mysql
# or
sudo service mysql startOn Windows:
Open Services (services.msc) and look for "MySQL" or "MySQL80" service. If Status is blank, right-click and select "Start".
Verify with telnet:
telnet hostname_or_ip 3306If connection succeeds, you'll see MySQL server version info. If it fails with "Connection refused" or timeout, MySQL is not listening.
Use telnet or nc (netcat) to verify network connectivity to the MySQL port:
# Test with telnet (install if needed: apt install telnetd)
telnet 192.168.1.100 3306
# Test with nc
nc -zv 192.168.1.100 3306
# Test DNS resolution (if using hostname instead of IP)
nslookup mysql.example.com
dig mysql.example.comIf telnet connects, you'll see a prompt with MySQL version. If it fails with "Connection refused" or timeout after 30 seconds, either the port is blocked or MySQL isn't listening.
If MySQL is running but you can't connect remotely, verify the bind-address setting.
View current configuration:
-- Connect locally (if possible)
mysql -u root
SHOW VARIABLES LIKE 'bind_address';Edit MySQL configuration file:
Find the configuration file (usually /etc/mysql/my.cnf, /etc/mysql/mysql.conf.d/mysqld.cnf, or /etc/my.cnf):
# For localhost-only connections (default):
[mysqld]
bind-address = 127.0.0.1
# For all interfaces:
[mysqld]
bind-address = 0.0.0.0
# For specific hostname/IP:
[mysqld]
bind-address = 192.168.1.100After editing, restart MySQL:
sudo systemctl restart mysqlEnsure you're using the correct hostname, IP address, and port:
# Connect with explicit parameters
mysql -h 192.168.1.100 -P 3306 -u root -p
# For remote host (verify IP is correct)
mysql -h remote-server.example.com -u root -p
# Find MySQL listening port
sudo netstat -tlnp | grep mysql
# or
sudo ss -tlnp | grep mysqlEnsure the hostname/IP resolves to the correct server and the port matches MySQL's listening port (default 3306).
Firewall rules must explicitly allow port 3306 from client hosts.
On Linux with UFW:
# Allow MySQL from any host
sudo ufw allow 3306/tcp
# Allow MySQL from specific IP
sudo ufw allow from 192.168.1.50 to any port 3306
# Check rules
sudo ufw statusOn Linux with iptables:
# Allow MySQL connections
sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
sudo iptables-save > /etc/iptables/rules.v4On Windows Firewall:
Go to Windows Defender Firewall → Advanced Settings → Inbound Rules → New Rule. Create rule allowing TCP port 3306.
On AWS Security Groups/Azure NSGs:
Add inbound rule allowing TCP port 3306 from your client IP address.
If MySQL was started with skip-networking enabled, no TCP/IP connections are accepted.
Check if skip-networking is active:
SHOW VARIABLES LIKE 'skip_networking';If the value is ON, disable it in the configuration file:
[mysqld]
# Comment out or remove this line
# skip-networkingThen restart MySQL:
sudo systemctl restart mysqlAlternatively, connect via Unix socket if available:
mysql -u root --socket=/tmp/mysql.sockFor local connections on Unix-based systems, MySQL can use sockets instead of TCP/IP.
Check socket location:
# Default socket locations
ls -la /tmp/mysql.sock
ls -la /var/run/mysqld/mysqld.sockConnect using socket:
mysql -u root --socket=/tmp/mysql.sockIf socket is missing or inaccessible:
Restart MySQL to regenerate the socket:
sudo systemctl restart mysqlIf a cron job removes old files from /tmp, configure MySQL to use a persistent socket location in /var/run/mysqld/ instead.
If connecting using a hostname instead of IP address, ensure DNS resolution works:
# Test DNS resolution
nslookup mysql.example.com
dig mysql.example.com
host mysql.example.com
# Test with IP instead to isolate DNS issues
mysql -h 192.168.1.100 -u root -p
# If IP works but hostname doesn't, it's a DNS issue
# Update /etc/hosts as a temporary workaround
echo "192.168.1.100 mysql.example.com" | sudo tee -a /etc/hostsIf DNS resolution fails, contact your network administrator or update DNS records pointing the hostname to the correct MySQL server IP.
ERROR 2003 is a client-side network error that occurs before MySQL protocol negotiation begins, making it distinct from server-side errors. The socket-based connection attempt is attempted first if connecting to localhost, and only falls back to TCP/IP if the socket is unavailable. For Docker containers, ensure the container is running and the port is exposed/mapped correctly (docker run -p 3306:3306). For Cloud SQL/RDS instances, verify the instance is available, not in a failed state, and security group/firewall rules allow inbound traffic. Connection pooling software (ProxySQL, pgBouncer) may mask the real error—test direct connectivity to the MySQL server first. The error code 2003 corresponds to SQLSTATE HY000 (general error). Some tools allow specifying connect_timeout to increase the wait time for slow networks; for example, mysql -h host --connect-timeout=10 waits up to 10 seconds.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL