What the message looks like
ERROR 2003 (HY000): Can't connect to MySQL server on 'db.example.com' (10061)Common causes
- The database service is not running or crashed, for example after an update or an OOM kill.
bind-address = 127.0.0.1in the config, so remote connections are refused.- Wrong port or hostname, or the client connects through a socket instead of TCP.
skip-networkingis set, so there is no TCP listener at all.- A firewall or security group blocks port 3306, often just for the new client IP.
Check
- Is the service running?
systemctl status mariadb --no-pager | head -n 5 - Which address and port does it listen on?
ss -lntp | grep 3306 - Test the port from the client
nc -vz db.example.com 3306 - Check bind-address and skip-networking
grep -rE '^(bind-address|skip-networking|port)' /etc/mysql/
Fix
- Start the service and read the journal for the reason it stopped. A restart without a cause only buys time.
- For remote clients set
bind-address = 0.0.0.0or the specific interface IP and restart. That opens the port on purpose. - Open the firewall for the client IP only, not for whole networks.
- On Windows, 10061 is usually the Windows firewall or a stopped service; 10060 is a timeout, so a wrong address or a dropping filter.
Typical scenario
A new application server is supposed to connect to the database at db.example.com and reports ERROR 2003 (HY000): Can't connect to MySQL server on 'db.example.com' (111), on Windows with (10061). On the database host the service listens, per the Debian default, only on 127.0.0.1. Check with ss -lntp | grep 3306 on which address the port is actually open.
FAQ
What is the difference between 2002 and 2003?
2002 is about the local socket, 2003 is the TCP connection to a host.
10061 versus 10060?
10061 means connection refused, so no listener. 10060 is a timeout, so a firewall or a wrong address.
How do I allow connections from other machines?
Set bind-address in the server configuration to the appropriate address, restart the service and create a user for the client host, for example 'app'@'10.0.0.%'. A user that exists only for localhost does not help foreign machines.
Is it safe to open the database port to the outside?
Better not to the internet. Open it only in the private network and restrict it by firewall to the application servers' addresses. For access from outside, SSH tunnels or VPN are suitable, and connections should use TLS when they cross an insecure network.
What does error 1130 mean in comparison?
With 1130 the connection worked, but the server rejects the client's host for that user. With 2003 no connection is made at all. So 1130 is a permissions problem in the server, 2003 a network, service or firewall problem.