Pivopen

mysqli_connect(): Too many connections

Symptoms

You may receive errors like the following on your website, or when trying to access MySQL from the command line or phpMyAdmin.

mysqli_connect(): (08004/1040): Too many connections
mysqli_real_connect(): (HY000/1040): Too many connections

Description 

This occurs when MySQL has reached its max_connections limit. Once the limit is reached, MySQL will no longer accept connections.

Workaround

Check for sleeping queries with the following command.

mysql -e "show processlist"|grep -c Sleep

Compare that against the max_connections setting for MySQL.

mysql -e "show variables like 'max_connections'"

If a large portion of the max_connections is being used by sleeping queries, you might consider lowering the wait_timeout setting. The wait_timeout setting can be changed in the /etc/my.cnf file. You can check the current wait_timeout with the following command.

mysql -e "show variables like 'wait_timeout'"

If there are not many sleeping queries, you might consider raising the max_connections limit. The max_connections setting can be changed in the /etc/my.cnf file as well.

MySQL will need to be restarted after making changes to the /etc/my.cnf file. This can be done with the following command.

/scripts/restartsrv_mysql

Shaz

Thank you for taking the time to read. If you want to support these posts, you can do so by bookmarking this link. Your support enables me to bring you amazing information and content each and everyday. Information you're not going to get anywhere else. It takes hours of study each day and several hours to produce and process the content.

Add comment

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.

Most popular

Most discussed