Console9

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

  1. Set bind-address to 0.0.0.0 in /etc/mysql/mysql.conf.d/mysqld.cnf:
bind-address = 0.0.0.0
  1. Restart MySQL:
sudo systemctl restart mysql
  1. Allow port 3306 through the firewall:
sudo ufw allow from 203.0.113.50 to any port 3306
  1. Verify MySQL is listening on port 3306:
ss -tlnp | grep 3306