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
This occurs when MySQL has reached its max_connections limit. Once the limit is reached, MySQL will no longer accept connections.
- 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'"
- Edit /etc/my.cnf.
- If a large portion of the max_connections is being used by sleeping queries, you might consider lowering the wait_timeout setting. 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.