How to fix ERROR 2003 (HY000): Can't connect to MySQL server on host in MySQL

MySQLINTERMEDIATEHIGHUpdated Dec 25, 2025· 250 views

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.

Quick fix

Fixes ERROR 2003 (HY000): Can't connect to MySQL server on host

# 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 start
  1. Verify the MySQL server is running
  2. Test connectivity from client to server
  3. Check MySQL bind address configuration
  4. Verify correct connection parameters
mysql — error
# 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 start
ERROR 2003 (HY000): Can't connect to MySQL server on host

What this error means

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).

Typical symptoms

  • Client tools (mysql CLI, MySQL Workbench) fail with "Can't connect to MySQL server" immediately upon connection attempt
  • Connection attempts timeout without receiving any response from the server
  • Telnet to the MySQL port returns "Connection refused" or times out
  • Remote connections fail while local socket connections may succeed
  • Application connection strings with hostname fail but localhost succeeds
  • Error occurs consistently on every connection attempt with the same error number 2003

Common causes

  1. MySQL server daemon (mysqld) is not running or has crashed
  2. Firewall blocking TCP/IP traffic on MySQL port (default 3306) from the client host
  3. MySQL bind-address configuration set to localhost (127.0.0.1) but connecting via hostname or different IP
  4. Incorrect hostname, IP address, or port number in the connection string
  5. DNS resolution failure preventing hostname from resolving to correct IP
  6. MySQL started with skip-networking option enabled, disabling all TCP/IP connections
  7. Unix socket file missing or inaccessible (for local connections)
  8. Network connectivity issues between client and server hosts
  9. MySQL listening on different port than specified in connection string

How to fix "ERROR 2003 (HY000): Can't connect to MySQL server on host"

1Verify the MySQL server is running

Check if the MySQL daemon is active on the target host.

On Linux/macOS:

bash
# 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 start

On Windows:
Open Services (services.msc) and look for "MySQL" or "MySQL80" service. If Status is blank, right-click and select "Start".

Verify with telnet:

bash
telnet hostname_or_ip 3306

If connection succeeds, you'll see MySQL server version info. If it fails with "Connection refused" or timeout, MySQL is not listening.

2Test connectivity from client to server

Use telnet or nc (netcat) to verify network connectivity to the MySQL port:

bash
# 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.com

If 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.

3Check MySQL bind address configuration

If MySQL is running but you can't connect remotely, verify the bind-address setting.

View current configuration:

sql
-- 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):

ini
# 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.100

After editing, restart MySQL:

bash
sudo systemctl restart mysql
4Verify correct connection parameters

Ensure you're using the correct hostname, IP address, and port:

bash
# 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 mysql

Ensure the hostname/IP resolves to the correct server and the port matches MySQL's listening port (default 3306).

5Configure firewall rules to allow MySQL traffic

Firewall rules must explicitly allow port 3306 from client hosts.

On Linux with UFW:

bash
# 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 status

On Linux with iptables:

bash
# Allow MySQL connections
sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
sudo iptables-save > /etc/iptables/rules.v4

On 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.

6Check for skip-networking option

If MySQL was started with skip-networking enabled, no TCP/IP connections are accepted.

Check if skip-networking is active:

sql
SHOW VARIABLES LIKE 'skip_networking';

If the value is ON, disable it in the configuration file:

ini
[mysqld]
# Comment out or remove this line
# skip-networking

Then restart MySQL:

bash
sudo systemctl restart mysql

Alternatively, connect via Unix socket if available:

bash
mysql -u root --socket=/tmp/mysql.sock
7Verify Unix socket availability (local connections)

For local connections on Unix-based systems, MySQL can use sockets instead of TCP/IP.

Check socket location:

bash
# Default socket locations
ls -la /tmp/mysql.sock
ls -la /var/run/mysqld/mysqld.sock

Connect using socket:

bash
mysql -u root --socket=/tmp/mysql.sock

If socket is missing or inaccessible:
Restart MySQL to regenerate the socket:

bash
sudo systemctl restart mysql

If a cron job removes old files from /tmp, configure MySQL to use a persistent socket location in /var/run/mysqld/ instead.

8Verify DNS resolution for hostname connections

If connecting using a hostname instead of IP address, ensure DNS resolution works:

bash
# 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/hosts

If DNS resolution fails, contact your network administrator or update DNS records pointing the hostname to the correct MySQL server IP.

Advanced notes

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.

Frequently asked questions

What does "ERROR 2003 (HY000): Can't connect to MySQL server on host" mean?
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).
How do I fix "ERROR 2003 (HY000): Can't connect to MySQL server on host"?
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.
What causes "ERROR 2003 (HY000): Can't connect to MySQL server on host"?
MySQL server daemon (mysqld) is not running or has crashed Firewall blocking TCP/IP traffic on MySQL port (default 3306) from the client host MySQL bind-address configuration set to localhost (127.0.0.1) but connecting via hostname or different IP
Is the "ERROR 2003 (HY000): Can't connect to MySQL server on host" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading