mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server
Fixes mysql-connector-python unable to reach the MySQL server. Use when connect() raises 2003. Not for 1045 access-denied (those reach the server).
TL;DR: Nothing answers at the host:port you gave. Start the MySQL server, or fix host/port (and bind-address/firewall) so the client reaches it.
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '[host]' (111 Connection refused)Fix it
- Check the server: sudo systemctl status mysql (or mysqld). Expected: active. If not, sudo systemctl start mysql.
- Confirm it listens where you connect: ss -ltn | grep 3306. Expected: a listening socket. Custom ports need port=[number] in connect().
- For remote hosts: check bind-address in my.cnf (the loopback address blocks remote) and firewall rules for 3306. Expected: reachable.
- Retry mysql.connector.connect with host [host], user [user], and your password. Expected: connects.
When this applies
- connect() raises 2003 Can't connect to MySQL server.
When it doesn't
- 1045 Access denied: you reach the server; credentials are the problem.
- Unknown database after connecting: the db name is wrong.
Compatibility
- mysql-connector-python 8.x; MySQL 5.7/8.
Why it happens
2003 is the network-layer failure: server down, wrong port, bind-address restricting to local, or firewall. The client never gets far enough to authenticate.
Edge cases
- In Docker, connect to the service name or container IP, not the loopback address, from other containers.
- skip-networking in my.cnf disables TCP entirely; only socket connections work then.
- The reworded host above stands in for whatever host your error names.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.