0

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.

  1. The database credentials in wp-config.php are 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 wp-config.php.
  2. 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.
  3. Restored both the contents of the wordpress directory and the database to a backup from a few days before the problem began.
  4. I tried to get debugging by adding define('WP_DEBUG', true); and define('WP_DEBUG_LOG', true); to the wp-config.php file and then "touching" wordpress/wp-content/debug.log, but the file does not populate with any data when I try to access the site.
  5. Scouring the Internet for this error and seeing if I had missed any common resolution to this error.
  6. Disabled plugins by moving wp-content/plugins to wp-content/plugins-bak. The command wp plugin disable just yields Error: Error establishing a database connection.
  7. Rebooted the WordPress and MySQL servers.

The WordPress machine is running Ubuntu Linux with Apache2. The database run MySQL 5.7.

  • 1
    Have you checked the resources allocated to the DB Server? In the past, I've seen issues where the DB server is "overloaded" (not always due to traffic, but bad queries/not enough dedicated resources). I would login to your host and check the server resources and see if there is a "high usage" warning every time you see the error. – Tom Mar 15 at 17:04
  • The database is clustered across three Galera nodes on very high-end machines. Their resource utilization is a fraction of what they are capable of. Many applications use this cluster and do not have any issues, including other WordPress sites. – David Baucum Mar 15 at 18:35
  • @DavidBaucum i would still make sure that you are not hitting mysql's max_connections issue 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 – Mikhail Mar 15 at 20:05
  • max_connections was 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 – David Baucum Mar 15 at 20:44
1

Try disabling the plugins - it may be that one of them is causing an error that is preventing the database connection from even executing and thus giving you an error regarding the database not being connected. Do those two sites have a common plugin?

| improve this answer | |
  • 1
    I had forgotten to add that to a troubleshooting step I had performed. I have tried moving wp-content/plugins to wp-content/plugins_bak but the site gave the same error. – David Baucum Mar 15 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.