I host multiple WordPress sites for clients on a single machine. Most of the site are up and running but two started giving the error "Error establishing a database connection". Each site has it's own database credentials, but connects to the same database.
Here is what I've done to troubleshoot.
- The database credentials in
wp-config.phpare accurate. I can use the mysql command on the cli to connect to the database from the WordPress server to the database using the credentials provided in
- Using the wp cli I have tried
wp db check. Each table in theh database comes back as "OK". This seems to indicate to me that the WordPress application is in fact able to connect to the MySQL server and issue commands.
- Restored both the contents of the
wordpressdirectory and the database to a backup from a few days before the problem began.
- I tried to get debugging by adding
define('WP_DEBUG_LOG', true);to the
wp-config.phpfile and then "touching"
wordpress/wp-content/debug.log, but the file does not populate with any data when I try to access the site.
- Scouring the Internet for this error and seeing if I had missed any common resolution to this error.
- Disabled plugins by moving
wp-content/plugins-bak. The command
wp plugin disablejust yields
Error: Error establishing a database connection.
- Rebooted the WordPress and MySQL servers.
The WordPress machine is running Ubuntu Linux with Apache2. The database run MySQL 5.7.
max_connectionsissue which is 151 by default. Knowing you have multiple sites working with same mysql instance it can be the case. Even overall server's resources consumption isn't high. dev.mysql.com/doc/refman/5.7/en/too-many-connections.html
max_connectionswas set to 200. I just bumped it to 500, but I'm still seeing the error. MySQL is reporting the following stats about connection. Threads Connected: 5 Threads Running: 1 Threads Created: 110 Threads Cached: 46 Rejected (over limit): 0