If you notice this error in your WordPress debug.log file (which is usually stored in wp-content/debug.log) that means that lots of people have connected to your site and that resulted in reaching the database connection limit.
Normally, this should not happen if the site’s content was served from the cache.
Maybe your site had lots of logged in users so the cache was skipped.
.. Or maybe the site’s links were accessed by passing parameters to the URL e.g. ?param=value which would normally make the caching plugin to not cache the page.
PHP Warning: mysqli_real_connect(): (HY000/1040): Too many connections in /var/www/sites/example.com/htdocs/wp-includes/wp-db.php on line 1753
How to get the current value for max_connections for MySQL/MariaDB
To get the current limit for max_connections you need to run the following command either in the mysql console or in phpMyAdmin.
SHOW VARIABLES LIKE "max_connections";
MariaDB [(none)]> SHOW VARIABLES LIKE "max_connections"; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 200 | +-----------------+-------+ 1 row in set (0.00 sec)
How to Update max_connections value for MySQL/MariaDB
To update the value right immediately you can run this SQL command. This won’t persist a server restart though.
SET GLOBAL max_connections = 500;
For this reason you need to also update that value in the MySQL/MariaDB config file.
If you’re using MariaDB server you can edit this file.
For MySQL the file should be
After you find the file update the value for max_connections
max_connections = 500
We set these values because the server has 8GB RAM. If your server has less memory than that, use a lower value such as 300.
Because we executed SET GLOBAL .. query we don’t need to reload the database server.
If you still want to do it you can run this command.
service mysql reload
Actually that may be a good idea because sometimes when we edit the config files may enter an extra character or invalid or not supported config field and that could cause the db server to not start during the next reboot.
This may block the server from fully loading or the database server won’t start at all.