Skip to content
MySQL

MySQL Error 2003

Can't connect to MySQL server on host:port (connection refused or timed out)

Applies to: MySQL client programs and libmysqlclient for MySQL 5.7, 8.0 and 8.4 (the 8.0 client shows host:port; the number in brackets is the operating system error)
Last technically reviewed 24 October 2026 on MySQL 8.0.46
The full message
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3399' (10061)
Other forms of this message
Host name instead of an IP address (Windows, refused)
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3399' (10061)
As shown in the MySQL manual (Linux, refused: 111)
ERROR 2003: Can't connect to MySQL server on 'host_name' (111)
PHP mysqli and PDO (mysqlnd) for the same refused port report 2002
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it
Error number
2003
SQLSTATE
HY000
Symbol
CR_CONN_HOST_ERROR
Product
MySQL Server
Versions
MySQL client programs and libmysqlclient for MySQL 5.7, 8.0 and 8.4 (the 8.0 client shows host:port; the number in brackets is the operating system error)
Last reviewed
24 October 2026

What it means

Error 2003 means the client could not open a TCP/IP connection to the MySQL server at that host and port, so it never reached the login stage.

The mysql client and other programs built on libmysqlclient raise 2003 when the TCP connection itself fails. It happens before any user name or password is sent, so it is never a privilege problem: the server either is not listening at that address and port, or something on the network is stopping the connection. The message shows the host and port the client tried (127.0.0.1:3399), which is the first thing to check, because a wrong port or host in a configuration file is a very common cause.

The number in brackets is the operating system's socket error. 10061 on Windows and 111 on Linux mean the connection was refused: the host answered, but nothing accepts connections on that port (the server is stopped, listens on another port, or listens only on another interface). A timeout code (10060 on Windows, 110 on Linux) usually means a firewall or security group silently drops the packets, or the address is wrong. PHP mysqli and PDO report the same failure as 2002 with the operating system text, and an unknown host name is a different client error, 2005.

Common causes

  • The MySQL server is not running on that host (stopped, crashed or still starting).
  • The port is wrong: the server listens on a non-default port (3307, 3310 and so on), or the client uses the default 3306 and the server does not.
  • The server listens only locally: bind_address is 127.0.0.1 or skip_networking is enabled, so remote clients are refused.
  • A firewall, cloud security group or network ACL blocks the port between the client and the server (often a timeout rather than a refusal).
  • A container port is not published, or the client inside a container uses localhost, which is the container itself rather than the database host.

Diagnose it

Read-only These statements only read metadata (information_schema, performance_schema and SHOW statements) or your own data. They do not change data, privileges or configuration, so they are safe to run first.

Which port and interfaces does the server listen on?

Run this on the server (for example over SSH with a local connection), then compare the values with the host and port in the error.

SHOW VARIABLES
WHERE Variable_name IN ('port', 'bind_address', 'skip_networking', 'admin_port', 'mysqlx_port');
What to look for

port is the classic protocol port the client must use. bind_address of * or 0.0.0.0 accepts connections on every interface, 127.0.0.1 only local ones. skip_networking ON means no TCP/IP connections at all. mysqlx_port (33060) is the X Protocol for MySQL Shell, not the port for the mysql client.

Has the server restarted recently?

SHOW GLOBAL STATUS LIKE 'Uptime';
What to look for

Seconds since the server started. A small value matching the time of the errors means the clients were refused while the server was down or restarting; look in the error log for the reason.

Is the port reachable from the client machine?

From the client, outside MySQL: telnet db.example.com 3306 (as the MySQL manual suggests) or, in PowerShell, Test-NetConnection db.example.com -Port 3306. A server that is listening answers with a greeting that includes its version; "connection refused" means nothing listens on that port, and a long wait means the packets are being dropped.

SHOW GLOBAL STATUS LIKE 'Connection_errors%';
What to look for

On the server, these counters only move for connections that reached it. If they stay at zero while clients get 2003, the connections are not arriving: look at the port, the bind address and the firewall rather than at MySQL accounts.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Connect to the right host and port

Client or network side

Take the port from SHOW VARIABLES LIKE 'port' on the server and use it everywhere: the application configuration, the [client] section of option files and connection strings. Use --no-defaults while testing so an old option file cannot supply a different port.

-- From a command prompt:
-- mysql --no-defaults -h db.example.com -P 3306 -u app -p

Start the server and find out why it stopped

Changes database state

If no mysqld process is running, start the service (for example systemctl start mysqld on Linux or the MySQL service in Windows Services). Then read the error log: a server that keeps stopping has a cause (disk full, memory, a configuration error) that a restart does not fix.

Let the server accept remote connections, safely

Changes configuration

If remote clients are refused because the server listens only on 127.0.0.1, set bind_address in the [mysqld] section of the option file (my.cnf or my.ini) to the server's private address or a list of addresses, for example bind_address = 10.0.0.12, and restart the server. bind_address cannot be changed at runtime.

Caution: Listening on a network interface exposes the server to everything that can reach it. Open the port in the firewall only for the application hosts, never to the whole internet, and create accounts for those specific hosts rather than '%'. A restart ends every connection, so plan it.

Open the firewall for the application hosts only, or use a tunnel

Changes configuration

When the port is blocked, allow it from the specific client addresses in the host firewall and any cloud security group. For administration from a laptop, an SSH tunnel avoids opening the port at all: ssh -L 3307:127.0.0.1:3306 user@db.example.com, then connect to 127.0.0.1 port 3307.

Examples

Connecting to a port where no server listens

Run with the mysql 8.0.46 client on Windows. 10061 is the Windows code for a refused connection; on Linux the same situation shows 111.

-- From a command prompt (the server runs, but not on port 3399):
-- mysql -h 127.0.0.1 -P 3399 -u app -p
SELECT 1;
Result
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3399' (10061)

Reproduced on MySQL 8.0.46, 24 October 2026.

The same with the host name localhost

On Windows, localhost is a TCP/IP connection, so the error is 2003. On Linux and macOS, localhost makes the client use the Unix socket file instead, and a stopped server gives error 2002.

-- mysql -h localhost -P 3399 -u app -p
SELECT 1;
Result
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3399' (10061)

Reproduced on MySQL 8.0.46, 24 October 2026.

A host name that does not resolve is a different error (2005)

When the name cannot be resolved, the client never tries to connect and reports 2005 (CR_UNKNOWN_HOST); 11001 is the Windows "host not found" code. Fix the host name or DNS, not the server.

-- mysql -h nosuchhost.invalid -u app -p
SELECT 1;
Result
ERROR 2005 (HY000): Unknown MySQL server host 'nosuchhost.invalid' (11001)

Reproduced on MySQL 8.0.46, 24 October 2026.

How to prevent it

Keep the database host and port in one place in each application's configuration, and check them in a deployment health check that opens a real connection. Monitor that mysqld is running and alert on restarts (a falling Uptime), so clients do not discover an outage through 2003.

Decide the network exposure deliberately: listen on a private interface only, allow the port from known application hosts, and use SSH tunnels or a bastion for administration. For containers, publish the port and connect by the service name rather than localhost.

Common questions

What does (10061) or (111) mean in MySQL error 2003?

It is the operating system error for the TCP connection. 10061 (Windows) and 111 (Linux) mean connection refused: the host is reachable but nothing listens on that port. 10060 or 110 mean the attempt timed out, usually a firewall dropping packets or a wrong address.

What is the difference between MySQL errors 2002 and 2003?

In the mysql client, 2002 is a failure to connect through the local Unix socket file (host localhost on Linux and macOS), and 2003 is a failure to connect over TCP/IP to a host and port. PHP mysqli and PDO report both situations as 2002, so read the text after the number.

Can a wrong password or missing privilege cause error 2003?

No. 2003 happens before the client sends a user name. A wrong password gives 1045 and a host without any matching account gives 1130, both of which prove that the network connection worked.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 24 October 2026; examples and diagnostics run on MySQL 8.0.46. Message templates checked against the server's error catalogue (perror) for that version.

Still stuck on a MySQL error?

Browse the full MySQL error library, or get hands-on help from an experienced SQL professional.