Knowledge
MySQL ERROR 1040: Too many connections
#Databases
This error means MySQL hit its max_connections limit and is refusing new clients. Raise the limit if it is genuinely too low, but first rule out leaked connections.
Published by Mark van Eijk on June 23, 2026 · 1 minute read
- About the error
- Why do I see this error
- Solution
- See what's using the connections
- Raise the limit
- Reclaim idle connections faster
- Fix the real cause in the app
About the error
ERROR 1040 (HY000): Too many connections
MySQL allows a fixed number of simultaneous client connections (max_connections, default 151). Once that ceiling is reached, every new connection is rejected until an existing one closes. For a web app this surfaces as failed requests across the whole site.
Why do I see this error
max_connectionsis genuinely too low for your traffic.- A connection leak: the application opens connections but never closes them.
- Long-running queries holding slots open, see
SHOW PROCESSLIST. - A connection pool misconfigured to exceed the server's limit.
- A real traffic spike.
Solution
See what's using the connections
You'll usually need an account with the SUPER privilege (MySQL reserves one extra slot for it) to get in when full:
SHOW PROCESSLIST;
SHOW STATUS WHERE Variable_name = 'Threads_connected';
If you see dozens of idle Sleep connections, that's a leak or idle sessions not being reaped, not a reason to keep raising the limit.
Raise the limit
Temporarily, without a restart:
SET GLOBAL max_connections = 300;
Permanently, in my.cnf under [mysqld]:
[mysqld]
max_connections = 300
Then restart MySQL. Don't set this arbitrarily high, each connection consumes memory, and a too-high value can exhaust RAM and take the server down harder than the original error.
Reclaim idle connections faster
Lower the idle timeouts so abandoned connections free their slots sooner:
wait_timeout = 120
interactive_timeout = 120
Fix the real cause in the app
For a Laravel app, make sure you're not opening connections in a loop and that long jobs run on a queue rather than holding a web request open. A leak will exhaust any limit you set. Related: SQLSTATE[HY000] [2002] Connection refused when MySQL can't be reached at all.
Subscribe to our newsletter
Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!
Related articles
Stream MySQL backup directly to S3 bucket
This error means MySQL hit its max_connections limit and is refusing new clients. Raise the limit if it is genuinely too low, but first rule out leaked connections.
Export MySQL database using command line
This error means MySQL hit its max_connections limit and is refusing new clients. Raise the limit if it is genuinely too low, but first rule out leaked connections.