The error “SQLSTATE[HY000] [1040] Too many connections” means MySQL reached its connection limit and refused new ones. Magento cannot serve any page without the database, so the store goes from working to completely down in an instant.
See what the connections are doing
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected';
SELECT command, COUNT(*) FROM information_schema.processlist GROUP BY command;
- Mostly “Query”: queries are running slowly, so each PHP request holds its connection longer and they pile up. The slow queries are the real problem (see slow query log).
- Mostly “Sleep”: connections are opened and left idle, often by a module that opens its own connection or by persistent connections.
Immediate relief
Raise the limit in /etc/mysql/my.cnf under [mysqld] and restart MySQL in a quiet period:
max_connections = 500
On AWS RDS, it’s a parameter group value. Each connection uses memory, so check the server can afford it.
The real fix
Connections pile up because something holds them too long. Fix slow queries, make sure full page cache works so fewer requests reach the database, and keep PHP-FPM workers within what the database can serve (see PHP-FPM saturation).
Catch it automatically
MageMonitor checks for this every few minutes as part of its Database checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.
