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.