MySQL 8.4Lab-verified · 2026-11-30

MySQL ERROR 1040 (08004): Too many connections

All connection slots allowed by max_connections are in use, so the server refuses the next login.

MySQL 8.4.13
1040 (08004): Too many connections

Jump to a cause

  1. 01Open connections reached max_connections

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-30 · container image mysql:8.4

ERROR 1040 happens at connect time, before any SQL runs. The server counts open connections and refuses a new one once the count reaches max_connections.

We set max_connections to 2 on MySQL 8.4, opened two sessions, and tried a third login.

01Open connections reached max_connections

With SET GLOBAL max_connections = 2, sessions A (lab_a) and B (lab_b) connected and ran a query normally. Session C, logging in as app_user with a correct password, was refused with ERROR 1040 (08004): Too many connections. The account and password were fine; there was simply no free slot.

SHOW VARIABLES LIKE 'max_connections' showed 2, and Max_used_connections showed 3, so the limit had been reached. After SET GLOBAL max_connections = 200, all three sessions connected.

Setup
Setuprun as root
CREATE USER app_user IDENTIFIED BY 'App#2026';
SET GLOBAL max_connections = 2;
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)
Reproduce3 sessions open at the same time (A, B, C), run in this order
Session Arun as lab_a
SELECT CURRENT_USER() AS who;
OUTPUT
+---------+
| who     |
+---------+
| lab_a@% |
+---------+
1 row in set (0.00 sec)
Session Brun as lab_b
SELECT CURRENT_USER() AS who;
OUTPUT
+---------+
| who     |
+---------+
| lab_b@% |
+---------+
1 row in set (0.00 sec)
Session Crun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'App#2026'
SELECT CURRENT_USER() AS who;
OUTPUT
ERROR 1040 (08004): Too many connections
Checkrun as root
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Max_used_connections';
OUTPUT
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 2     |
+-----------------+-------+
1 row in set (0.01 sec)

+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| Max_used_connections | 3     |
+----------------------+-------+
1 row in set (0.00 sec)
Fixrun as root
SET GLOBAL max_connections = 200;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Before raising the limit, confirm with Max_used_connections that it was actually reached.

After the fix3 sessions open at the same time (A, B, C), run in this order
Session Arun as lab_a
SELECT CURRENT_USER() AS who;
OUTPUT
+---------+
| who     |
+---------+
| lab_a@% |
+---------+
1 row in set (0.00 sec)
Session Brun as lab_b
SELECT CURRENT_USER() AS who;
OUTPUT
+---------+
| who     |
+---------+
| lab_b@% |
+---------+
1 row in set (0.00 sec)
Session Crun as app_user
$ mysql -h 127.0.0.1 -u app_user -p'App#2026'
SELECT CURRENT_USER() AS who;
OUTPUT
+------------+
| who        |
+------------+
| app_user@% |
+------------+
1 row in set (0.00 sec)

FAQ

How do I check the current max_connections in MySQL?

Run SHOW VARIABLES LIKE 'max_connections';. To see how close you have come to it, check SHOW STATUS LIKE 'Max_used_connections'; — if it is at or above the limit, ERROR 1040 was caused by the limit.

Is ERROR 1040 a wrong password problem?

No. In our test the same app_user and password were refused with 1040 and then connected fine once the limit was raised. A wrong password gives ERROR 1045 instead.

What is the SQLSTATE of ERROR 1040?

08004 (server rejected the connection), as shown in ERROR 1040 (08004): Too many connections.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13