MySQL PDO Too many connections

MySQLpdo

I have an application that is constantly inserting to a stats table. The average number of open connections is usually about 20 to 22.

There is also a processing script in PHP run by a cron that runs every 30 minutes. Around 2am UTC it takes about 10 minutes to process which is the longest amount of time during a day.

Around this time, I'm getting about 8000 PDOException: SQLSTATE[08004] [1040] Too many connections errors.

The max_connections is set to 500.

I've observed that by doing SHOW PROCESSLIST; I don't usually see any queries in the Info column. While the cron is running, I do see the query for the cron in the Info column and then the SQL inserts quickly pile up below it.

I don't really know a great deal about configuring MySQL but it seems like the inserts to the stats table are getting queued and surpassing the max connection limit while the Cron script is running.

What can be causing this and which configuration settings should I look at changing?

Best Answer

Can you check below parameters? try to increase the max_user_connections value and if application hold connection for long reduce the wait_timeout.

max_user_connections=[value]
wait_timeout = [value]