mysqldude
Error codes › 2003

MySQL & MariaDB error 2003: Can't connect to MySQL server on host

MySQLCan't connect to MySQL server on '…:…' (…)
MariaDBCan't connect to server on '…' (…)
Example from our test runs: Can't connect to MySQL server on '127.0.0.1:3307' (111) (8.0.46)

A TCP connection to the server failed. Nothing is listening on that host and port, or a firewall, bind-address or wrong port is in the way.

MySQLMariaDB
SymbolCR_CONN_HOST_ERRORCR_CONN_HOST_ERROR
SQLSTATEHY000HY000
TypeClient library errorClient library error
Versionsevery release since 5.0 activesince 10.2.44 active

What it means

The client opened a TCP connection to host:port and the operating system refused it or it timed out. Like 2002, it is raised by the client before the server is involved. MariaDB’s client never reports 2003: its client library (Connector/C) returns 2002 for refused TCP connections too, so on MariaDB a “2002” can be a TCP problem, not a socket problem. Our tests confirm this on MariaDB 10.6 to 11.8. The trailing number is the OS error: (111) / (10061) connection refused (nothing listening), (110) / (10060) timed out (usually a firewall), (113) no route to host.

Why it happens

  • The server is stopped, or listens on a different port (SELECT @@port).
  • The server only listens on localhost: bind-address = 127.0.0.1 (the default in many packages) or skip-networking, so remote clients are refused.
  • A firewall or cloud security group blocks port 3306.
  • Docker: the port isn’t published, or the app uses localhost instead of the database container’s service name.

How to fix it

  1. On the server: is it running, and on which address and port? ss -ltnp | grep mysqld and SELECT @@port, @@bind_address;.
  2. To accept remote connections, set bind-address = 0.0.0.0 (or the server’s IP) in my.cnf and restart, then make sure an account exists for the remote host (otherwise you will see 1045 or 1130).
  3. Open the port in the firewall or security group, ideally only for the application servers.
  4. Test from the client machine: nc -vz dbhost 3306. If that fails, the problem is the network, not MySQL.

Reproduce it yourself

These steps are the exact test our harness runs. Use a scratch server, never production.

  1. Connect with mysql -u root -p and create a scratch database:

    CREATE DATABASE demo;
    USE demo;
  2. In a shell on the database host:

    mysql -uroot -p -h127.0.0.1 -P3307 -e 'SELECT 1'

You get: ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3307' (111)(9.7.4)

Verified fixes

  1. Check the port the server really listens on, then connect to it

    On the server, check the port and address it listens on:

    SELECT @@port, @@bind_address;

    Then connect to that port (and check a firewall isn't in the way):

    mysql -u root -p -h 127.0.0.1 -P 3306
    nc -vz dbhost 3306

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
Connect over TCP to a port where no server is listening (MariaDB's client reports this as 2002)
repro
✓ 2003✓ 2003✓ 2003✓ 2003✓ 2003✓ 2002✓ 2002✓ 2002✓ 2002
Check the port the server really listens on, then connect to it
fix
✓✓✓✓✓✓✓✓✓
Connect over TCP to a port where no server is listening (MariaDB's client reports this as 2002) repro
MySQL 5.6✓ 20035.7✓ 20038.0✓ 20038.4✓ 20039✓ 2003
MariaDB 10.6✓ 200210.11✓ 200211.4✓ 200211.8✓ 2002
Check the port the server really listens on, then connect to it fix
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9

Related errors

  • 2002 CR_CONNECTION_ERRORexplained
  • 2013 CR_SERVER_LOSTexplained
  • 1045 ER_ACCESS_DENIED_ERRORexplained
  • 1130 ER_HOST_NOT_PRIVILEGEDexplained
How the message changed between versions
MySQL fromSymbolMessage
5.0.96CR_CONN_HOST_ERRORKeine Verbindung zu MySQL Server auf %-.100s (%d)
5.5.63CR_CONN_HOST_ERRORCan't connect to MySQL server on '%-.100s' (%d)
8.0.26CR_CONN_HOST_ERRORCan't connect to MySQL server on '%-.100s:%u' (%d)