Docs / Troubleshooting / How to Fix MySQL Too Many Connections Error

How to Fix MySQL Too Many Connections Error

By Admin · Mar 1, 2026 · Updated Apr 25, 2026 · 27 views · 2 min read

What Causes This Error?

MySQL returns "Too many connections" when the number of simultaneous client connections reaches the max_connections limit. The default is typically 151, which can be insufficient for busy applications on a Breeze.

Check Current Status

mysql -u root -p -e "SHOW VARIABLES LIKE 'max_connections';"
mysql -u root -p -e "SHOW STATUS LIKE 'Threads_connected';"
mysql -u root -p -e "SHOW STATUS LIKE 'Max_used_connections';"

Temporary Fix (No Restart)

Increase the limit immediately in a running MySQL instance:

mysql -u root -p -e "SET GLOBAL max_connections = 300;"

This takes effect immediately but resets on restart.

Permanent Fix

Edit the MySQL configuration file:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add or update under the [mysqld] section:

[mysqld]
max_connections = 300
sudo systemctl restart mysql

Investigate Root Cause

Before simply raising the limit, identify why connections are exhausted:

# Show all active connections
mysql -u root -p -e "SHOW PROCESSLIST;"

# Find connections by user
mysql -u root -p -e "SELECT user, COUNT(*) as count FROM information_schema.processlist GROUP BY user ORDER BY count DESC;"

# Find sleeping connections
mysql -u root -p -e "SELECT user, host, time FROM information_schema.processlist WHERE command='Sleep' ORDER BY time DESC LIMIT 20;"

Common Causes and Solutions

  • Connection leaks — application not closing database connections; fix your code to use connection pooling or ensure proper cleanup
  • Long-running queries — blocking other connections; optimize slow queries
  • Too many idle connections — reduce wait_timeout to close idle connections sooner
# Close idle connections after 5 minutes instead of 8 hours
SET GLOBAL wait_timeout = 300;
SET GLOBAL interactive_timeout = 300;

Was this article helpful?