If you run into the WordPress Error Establishing a Database Connection after moving your site, or maybe it just came out of nowhere, here is how to fix it.
Check Your Database Service
Check to be sure that there are no service issues related to your hosting that may be impacting your website. If you have multiple websites connected to databases on the same host check to make sure they are online. A large influx of traffic to your website for example, can overwhelm your server resulting in errors like this.
Check the wp-config.php File
This file is located in the root directory of your WordPress installation. Verify that the correct database information is listed to include:
- Database Name
- Database User Name
- Database Password
- Database Host
If you recently moved your WordPress site to another host or modified your existing database service you will need to update the above to point to the correct database.
Evaluate any Recent Changes
If you are seeing this error and recently made a change to a plugin, website file, etc. It is likely that this error may be a result of a misconfiguration, or compatibility issue. Since the Error Establishing a Database Connection notice is directly related to the website communication with the database, it is always best to troubleshoot backwards evaluating your most recent website change first.