Error
Error Code: 2003

MySQL Error 2003: Server Connection Failure

📦 MySQL
📋

Description

This error indicates that the MySQL client application was unable to establish a network connection with the MySQL server. It typically occurs when the client cannot reach the specified host and port, preventing any database operations from succeeding.
💬

Error Message

Can't connect to MySQL server on '%s:%u' (%d)
🔍

Known Causes

4 known causes
⚠️
MySQL Server Offline
The MySQL server process is not actively running on the specified host, preventing any incoming connections.
⚠️
Wrong Connection Details
The client application is attempting to connect to an incorrect hostname, IP address, or port number where the MySQL server is not listening.
⚠️
Firewall Blockage
A firewall on either the client or server machine is blocking the network traffic on the MySQL port (default 3306).
⚠️
Network Connectivity Issues
General network problems, such as DNS resolution failures or routing issues, are preventing communication between the client and server.
🛠️

Solutions

5 solutions available

1. Check MySQL Server is Running easy

Ensure the server is started and listening

1
Check MySQL status
# Linux
sudo systemctl status mysql

# macOS
brew services list | grep mysql

# Windows
net start | findstr MySQL
2
Start MySQL if stopped
# Linux
sudo systemctl start mysql

# macOS  
brew services start mysql

# Windows
net start MySQL80

2. Check Host and Port easy

Verify correct hostname and port number

1
Verify MySQL is listening
# Check if MySQL is listening on expected port
netstat -tlnp | grep 3306
# or
ss -tlnp | grep 3306
2
Test connection with correct port
mysql -u user -p -h hostname -P 3306
3
Check bind-address in my.cnf
[mysqld]
# 0.0.0.0 allows remote connections
bind-address = 0.0.0.0
# 127.0.0.1 only allows local connections
# bind-address = 127.0.0.1

3. Check Firewall Rules medium

Allow MySQL port through firewall

1
Linux (iptables/ufw)
# UFW
sudo ufw allow 3306/tcp

# iptables
sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
2
Windows Firewall
netsh advfirewall firewall add rule name="MySQL" dir=in action=allow protocol=tcp localport=3306
3
Check cloud provider security group
# AWS/GCP/Azure - add inbound rule:
# Protocol: TCP
# Port: 3306
# Source: Your IP or range

4. Fix Network Connectivity medium

Troubleshoot network issues

1
Test basic connectivity
# Ping the host
ping mysql-server-host

# Test port with telnet
telnet mysql-server-host 3306

# Or with nc
nc -zv mysql-server-host 3306
2
Check DNS resolution
nslookup mysql-server-host
# or
dig mysql-server-host
3
Try IP address instead of hostname
mysql -u user -p -h 192.168.1.100 -P 3306

5. Check skip-networking Setting medium

Ensure MySQL allows TCP connections

1
Check if skip-networking is enabled
# In MySQL (if you can connect locally):
SHOW VARIABLES LIKE 'skip_networking';
2
Disable skip-networking in my.cnf
[mysqld]
# Remove or comment out:
# skip-networking

# Make sure this is NOT set:
# skip-networking = 1
3
Restart MySQL
sudo systemctl restart mysql
🔗

Related Errors

5 related errors