1040 MySQL Origin: Data OSI layer 7 · Application Last updated 13 Oct 2026

MySQL ERROR 1040 (08004): Too many connections

MySQL reached max_connections and refuses new clients.

Exact message you may see Too many connectionsremaining connection slots are reserved
Seen on: MySQL Node.js PostgreSQL

Meaning

Each client connection uses memory, so MySQL caps them (default 151). Leaking connections, unbounded worker counts, persistent connections from many PHP-FPM children, or slow queries piling up exhaust the limit. Shared hosting often has a per-user cap (max_user_connections, error 1203).

Common causes

  • Connections not closed / connection leaks
  • Too many app workers each holding a pool
  • Slow queries keeping connections busy so new ones pile up
  • Persistent connections × many PHP-FPM processes
  • Per-user limit on shared hosting

⚡ Quick fix

  1. See who is connected: SHOW PROCESSLIST;
  2. Fix slow queries causing pile-ups
  3. Right-size pools: workers × pool size < max_connections
  4. Raise max_connections only if RAM allows

Detailed fix by platform

MySQL

  1. Inspect and adjust:
    sql
    SHOW VARIABLES LIKE 'max_connections';
    SHOW STATUS LIKE 'Max_used_connections';
    SELECT user, host, COUNT(*) FROM information_schema.processlist GROUP BY user, host ORDER BY 3 DESC;
    SET GLOBAL max_connections = 300;   -- also persist in my.cnf

Node.js

  1. Create ONE pool per process (e.g. mysql2.createPool({ connectionLimit: 10 })), not a connection per request.

How to diagnose

  1. Usage — Max_used_connections vs max_connections
  2. Who — Which user/host holds most connections?
  3. State — Many in Sleep (leak) or Query (slow)?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

1049 — MySQL ERROR 1049 (42000): Unknown database 'x' (MySQL)10491114 — MySQL ERROR 1114 (HY000): The table 'x' is full (MySQL)11141418 — MySQL ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (MySQL)14182002 — MySQL ERROR 2002 (HY000): Can't connect to local MySQL server through socket (MySQL)20022003 — MySQL ERROR 2003 (HY000): Can't connect to MySQL server on 'host:3306' (111) (MySQL)20032013 — MySQL ERROR 2013 (HY000): Lost connection to MySQL server during query (MySQL)2013508 — HTTP 508 Loop Detected (Resource Limit Is Reached) (HTTP)508509 — HTTP 509 Bandwidth Limit Exceeded (HTTP)5091040

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.