mysqldude
Error codes › 1040

MySQL & MariaDB error 1040: Too many connections

Error messageToo many connections
Example from our test runs: Too many connections (5.6.51)

All max_connections slots are in use, so new clients are refused. Usually leaked or idle pooled connections or a traffic spike, rarely a limit that is really too low.

MySQLMariaDB
SymbolER_CON_COUNT_ERRORER_CON_COUNT_ERROR
SQLSTATE0800408004
TypeServer errorServer error
Versionsevery release since 5.0 activeevery release since 5.5 active

What it means

The server already has max_connections client connections (151 by default) and refuses another one. One extra slot is kept for an account with SUPER (MySQL 8.0+: CONNECTION_ADMIN), so an administrator can still log in and see what’s going on, as long as nobody else used that slot already.

Why it happens

  • Applications open connections and don’t close them, or pools are sized so that pool size × application instances is more than the server allows.
  • Slow queries or lock waits make connections stay busy longer, so a normal traffic peak needs many more of them at once.
  • Many connections in Sleep state for a long time: wait_timeout (8 hours by default) keeps abandoned connections open.
  • A per-account limit gives a different error: 1203 for max_user_connections, 1226 for MAX_CONNECTIONS_PER_HOUR.

How to fix it

  • Log in as an admin and see who holds the connections: SHOW FULL PROCESSLIST; works everywhere. On MySQL 8.0.22+ the preferred form is SELECT user, host, command, time, state FROM performance_schema.processlist ORDER BY time DESC;, because SHOW PROCESSLIST and information_schema.PROCESSLIST raise deprecation warning 1287 there (tested on 8.0.46, 8.4 and 9.7). Group by user, host to find the application.
  • KILL long-idle connections as a short-term relief, then fix the pool settings or the leak.
  • Lower wait_timeout for application accounts so abandoned connections are dropped sooner.
  • MariaDB won’t go below max_connections = 10; MySQL allows 1.
  • Raise max_connections only if the server has the memory for it. Each connection uses per-session buffers, so a large value can push the server into swap or the out-of-memory killer under load.
  • SHOW GLOBAL STATUS LIKE 'Max_used_connections'; shows the peak since the last restart.

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. As an admin, lower the limit so it is easy to reach (don't do this on a shared server).

    SET GLOBAL max_connections = 10;
  3. Open one connection as a normal (non-admin) account and leave it open, then try a second one:

    mysql -u appuser -p -h 127.0.0.1 -e 'SELECT SLEEP(30)' &
    mysql -u appuser -p -h 127.0.0.1 -e 'SELECT 1'
  4. Put the limit back (151 is the default).

    SET GLOBAL max_connections = 151;

You get: ERROR 1040 (08004): Too many connections(11.8.9)

Verified fixes

  1. See who holds the connections (an admin account gets one extra slot for this). MySQL 8.0+ warns 1287: SHOW PROCESSLIST is deprecated in favour of performance_schema.processlist

    SHOW FULL PROCESSLIST;

Tested on

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
More clients connect than max_connections allows (here it is lowered to 10, MariaDB's minimum)
repro
✓ 1040✓ 1040✓ 1040✓ 1040✓ 1040✓ 1040✓ 1040✓ 1040✓ 1040
See who holds the connections (an admin account gets one extra slot for this). MySQL 8.0+ warns 1287: SHOW PROCESSLIST is deprecated in favour of performance_schema.processlist
fix
✓✓⚠ 1287⚠ 1287⚠ 1287✓✓✓✓
More clients connect than max_connections allows (here it is lowered to 10, MariaDB's minimum) repro
MySQL 5.6✓ 10405.7✓ 10408.0✓ 10408.4✓ 10409✓ 1040
MariaDB 10.6✓ 104010.11✓ 104011.4✓ 104011.8✓ 1040
See who holds the connections (an admin account gets one extra slot for this). MySQL 8.0+ warns 1287: SHOW PROCESSLIST is deprecated in favour of performance_schema.processlist fix
MySQL 5.6✓5.7✓8.0⚠ 12878.4⚠ 12879⚠ 1287
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
What the warnings and failures say (1)
  • See who holds the connections (an admin account gets one extra slot for this). MySQL 8.0+ warns 1287: SHOW PROCESSLIST is deprecated in favour of performance_schema.processlist (MySQL 8.0, MySQL 8.4, MySQL 9): warning 1287: 'INFORMATION_SCHEMA.PROCESSLIST' is deprecated and will be removed in a future release. Please use performance_schema.processlist instead

Related errors

  • 1203 ER_TOO_MANY_USER_CONNECTIONS
  • 2013 CR_SERVER_LOSTexplained
  • 1226 ER_USER_LIMIT_REACHED