MySQL: ERROR 2003 (HY000): Can't connect to MySQL server on host
Diagnose and fix MySQL remote connection errors caused by bind-address, firewall rules, or skip-networking.
MySQL produces "ERROR 2003 (HY000): Can't connect to MySQL server on '203.0.113.50'" when a remote TCP connection to the MySQL port (3306) fails.
What Causes "ERROR 2003" in MySQL
MySQL's
bind-address directive restricts which IP addresses the server accepts connections from. The default
bind-address = 127.0.0.1 allows only local connections. Remote clients receive "Can't connect."
A firewall ( UFW, iptables, cloud security group) blocks inbound TCP port 3306.
The
skip-networking option in the MySQL configuration disables TCP connections entirely, allowing only Unix socket connections.
How to Fix
- Set
bind-addressto0.0.0.0in/etc/mysql/mysql.conf.d/mysqld.cnf:
bind-address = 0.0.0.0- Restart MySQL:
sudo systemctl restart mysql- Allow port 3306 through the firewall:
sudo ufw allow from 203.0.113.50 to any port 3306- Verify MySQL is listening on port 3306:
ss -tlnp | grep 3306