How to Fix the Error Establishing a Database Connection in WordPress
1. Check Your WordPress Database Credentials
The most frequent cause of the database connection error is incorrect credentials, especially if you’ve recently migrated your WordPress site to a new host.
Your WordPress database credentials are stored in the wp-config.php file, which contains essential configuration settings, including database details.
If you’re new to editing the wp-config.php file, check out our beginner’s guide on how to edit it for detailed instructions.
Focus on these specific lines in the wp-config.php file:
Ensure that the database name, username, password, and host details in your wp-config.php file are correct.
You can verify these details through your WordPress hosting account dashboard. For this guide, we’ll use Bluehost as an example, but the steps will be similar with other hosting providers.
Log in to your hosting account, click on the ‘Website’ tab in the left column, then switch to the ‘Advanced’ tab. Scroll down to the ‘Database’ section and click the ‘Manage’ button next to it. This will open the MySQL Databases page in cPanel.
On this page, you can find your database name and username under the ‘Current Database’ section. Copy these details into a notepad for reference and add them to your wp-config.php file.
Next, scroll down to the ‘Current Users’ section and click the ‘Change Password’ link next to your database name. Here, you can set a new password for your database.
After confirming all your database details, update them in your wp-config.php file as needed.
Visit your website again to see if the database connection error is resolved. If the error persists, there may be another issue that needs addressing.
2. Check Your Database Host Information
If you’re sure your database name, username, and password are correct, the next step is to verify your database host information.
While most WordPress hosting providers use localhost as the database host, some managed WordPress hosts may use a different server for databases. If that’s the case, localhost won’t be the correct host.
To confirm the correct database host, you’ll need to contact your WordPress hosting provider for accurate details.