Short answer: ERROR 1040 (08004): Too many connections means MariaDB/MySQL has reached max_connections (MariaDB default 151). Connect as root, which gets one reserved extra connection, and run mysql -e "SHOW PROCESSLIST" and mysql -e "SHOW GLOBAL STATUS LIKE 'Threads_connected'; SHOW VARIABLES LIKE 'max_connections'" to see who holds the slots. Kill idle or runaway queries and fix the slow query or leaking application, then set a sensible max_connections and a shorter wait_timeout (default 28800 seconds) under [mysqld] in /etc/my.cnf, restarting with /usr/local/cpanel/scripts/restartsrv_mysql, or apply them live with SET GLOBAL. (Reviewed October 2026.)
Applies to cPanel & WHM with MariaDB 10.6 to 11.8 or MySQL 8.0/8.4
The exact message is ERROR 1040 (08004): Too many connections in the mysql client, or SQLSTATE[HY000] [1040] Too many connections in PHP and WordPress logs. Both mean the server has reached max_connections; a per-user limit gives a different error (1203, max_user_connections).
Get the server responding first
If every site on the box is down, do not start tuning. Get in and clear the pile-up. MariaDB reserves one extra connection for a SUPER user, so as root you can usually still connect even when the limit is hit:
Table of Contents
mysql -e "SHOW PROCESSLIST" | head -40
mysql -e "SHOW GLOBAL STATUS LIKE 'Threads_connected'; SHOW VARIABLES LIKE 'max_connections'"
If the process list is full of Sleep rows from one database user, that user’s application is opening connections and never closing them. Kill the sleepers older than a minute to free the server immediately:
mysql -Nse "SELECT CONCAT('KILL ',id,';') FROM information_schema.processlist WHERE command='Sleep' AND time>60" | mysql
If instead the list is full of long-running SELECTs in state Sending data or Copying to tmp table, one query is holding everything up. Note the query text, then kill only those IDs. Restarting MariaDB is the last resort — it works, but you lose the evidence.
Find the real cause
“Too many connections” is a symptom. Before raising any limit, spend five minutes on where the connections came from:
- A slow query. Enable the slow log for an hour:
SET GLOBAL slow_query_log=1; SET GLOBAL long_query_time=2;then read/var/lib/mysql/<host>-slow.logor runmysqldumpslow -s t -t 10on it. A query that takes eight seconds on a busy WordPress site will hold dozens of connections open behind it. - A traffic spike or bot.
tail -5000 /etc/apache2/logs/domlogs/<domain> | awk '{print $1}' | sort | uniq -c | sort -rn | headshows whether one IP is hammering a site. Block it in CSF and the connections drain on their own. - A leaking application. Persistent connections (
mysqli.allow_persistent, PDOATTR_PERSISTENT) with PHP-FPM can multiply: every FPM child keeps its own. Check withSHOW PROCESSLISTgrouped by user. - Lock waits.
SHOW ENGINE INNODB STATUS\GunderTRANSACTIONSshows if queries are queued behind a lock, often from a plugin doingALTER TABLEor a backup job withLOCK TABLES.
The mysql-health-snapshot script prints most of these numbers on one page.
Set the limit properly
cPanel ships max_connections=151, the MariaDB default. On a shared server with 50+ sites it is too low; on a single-site VPS with 2 GB of RAM it may be too high. Each connection can use up to sort_buffer_size + read_buffer_size + read_rnd_buffer_size + join_buffer_size + thread_stack (typically 1–4 MB), so 500 connections on a small box can run you out of memory and make things worse.
Edit /etc/my.cnf under [mysqld]:
max_connections = 300
wait_timeout = 120
interactive_timeout = 120
open_files_limit = 65535
wait_timeout is the important one: it closes idle connections after 120 seconds instead of the default 8 hours, which is what lets a leaking application fill the table in the first place. Restart with /usr/local/cpanel/scripts/restartsrv_mysql in a quiet minute, or apply live without restarting:
mysql -e "SET GLOBAL max_connections=300; SET GLOBAL wait_timeout=120;"
Live changes are lost on restart, so put them in my.cnf too.
Undo the change
Both variables are dynamic, so you can put the MariaDB defaults back without a restart: max_connections 151 and wait_timeout 28800 (8 hours). Then remove or comment out the lines you added under [mysqld] in /etc/my.cnf so the defaults survive the next restart.
mysql -e "SET GLOBAL max_connections=151; SET GLOBAL wait_timeout=28800;"
# after editing /etc/my.cnf:
/usr/local/cpanel/scripts/restartsrv_mysql
Existing sessions keep the wait_timeout they started with; only new connections pick up the restored value.
Stop it from coming back
Give PHP-FPM a ceiling per site (pm.max_children) in WHM → MultiPHP Manager → PHP-FPM settings, so one busy site cannot open more MySQL connections than the server can serve. Turn on object caching (Redis or LiteSpeed Cache’s object cache) for WordPress sites; it cuts query count by 60–80% on typical pages. And keep the slow log on permanently with long_query_time=5 — it costs nothing and tells you which site to look at next time.
MySQL too many connections at a glance

Official documentation (checked 8 October 2026): MySQL reference manual · MariaDB documentation · MariaDB error 1040 (SQLSTATE 08004) and 1203 (42000) · MariaDB max_connections (default 151, reserved SUPER connection), wait_timeout (28800), thread_cache_size · MySQL: Too many connections and the extra CONNECTION_ADMIN/SUPER connection · cPanel: enable the slow query log, my.cnf, restartsrv_mysql, mysqldumpslow · cPanel: supported MySQL/MariaDB versions per OS.
Related guides: Tuning InnoDB on MariaDB 11/12 for cPanel shared hosting: buffer pool, redo log and I/O · MariaDB won’t start after an upgrade: InnoDB recovery, mariadb-upgrade and sql_mode issues · Installing and switching PHP versions in EasyApache 4 (8.2 to 8.5).
Next step: a server that stops answering altogether is a different problem; the MariaDB watchdog script detects a real hang and restarts only when it is safe.
