Security

Fix: mysqli_sql_exception too many connections

Here in this article you will know how to fix mysqli_sql_exception too many connections in cpanel

Error mysqli_sql_exception too many connections

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
PHP Warning: mysqli::__construct(): (08004/1040): Too many connections in
mysqli_sql_exception too many connections

When a MySQL server is initially installed, it will have 150 as the default value for maximum permitted number of simultaneous client connections. This value can be adjusted further in servers.

mysqli_sql_exception too many connections

An additional admin connection is also possible to monitor these client connections. This extra connection is reserved for use by accounts that have CONNECTION_ADMIN or SUPER user privilege.

The number of connections is defined by ‘max_connections’ value. When the number of client connections exceed this value, MySQL shows ‘Too many connections’ error.

This can happen in multiple scenarios, and the fix for the error would vary with the actual cause. Here, we’ll see the various causes that trigger MySQL ‘Too many connections’ error.

Your MySQL database only allows so many connections at the same time. If you connect to MySQL via PHP, then you generally open a new connection every time a page on your site loads. So if you’ve got too much traffic to your site this can cause this issue.

General procedure and fix,

The default max_connections setting for MySQL is 151. For some servers, this setting may need adjusting. This article provides the procedure to adjust this setting.

Access the server’s command line as the ‘root’ user via SSH or “Terminal” in WHM.
Check the current max_connections setting.

[root@server ~]cPs# mysql -e "show variables like 'max_connections';"
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 100 |
+-----------------+-------+

Open /etc/my.cnf in your preferred text editor.
Locate the max_connections entry or add the entry to the end of the file if one doesn’t exist.

max_connections=151

Set the max_connections value to the desired value.
Save the changes and exit the text editor.
Restart the MySQL service.

/usr/local/cpanel/scripts/restartsrv_mysql

Verify that the max_connections setting has been updated.

[root@server ~]cPs# mysql -e "show variables like 'max_connections';"
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 150 |
+-----------------+-------+

 

If the mails are not delivering and in queue , you don’t know how to delete pending mail in Exim queue click here.