How to Resolve the “MySQL – Too Many Connections” Error
This error occurs when the number of active MySQL connections reaches the maximum limit defined in the MySQL configuration.
1. Check the Current Connection Limit
Run the following SQL command:
SHOW VARIABLES LIKE 'max_connections';2. Check Current Active Connections
SHOW STATUS LIKE 'Threads_connected';3. Increase the MySQL Connection Limit
Option A: Temporary Increase (Immediate Effect, but Resets After Restart)
SET GLOBAL max_connections = 500;(You can set any number as needed.)
Option B: Permanent Increase (Recommended)
Edit the MySQL configuration file:
Linux:
/etc/my.cnfor/etc/mysql/my.cnfWindows:
my.ini
Add or update:
[mysqld]
max_connections = 500Then restart MySQL:
Linux:
sudo systemctl restart mysqlWindows: Restart MySQL service from Services.
4. Identify Scripts That Keep Connections Open
Sometimes the real issue is:
Unoptimized PHP scripts
Long-running queries
Missing
mysqli_close()Too many concurrent requests
Check the process list:
SHOW FULL PROCESSLIST;Last updated
Was this helpful?