How to Fix Error Establishing a Database Connection (Complete Guide)

- Writtetn by Helal Uddin,
- Last Updated

Today I will teach you exactly how to fix error establishing a database connection in WordPress.
In fact, this step-by-step guide helped my client Foxcoders.com fix this error smoothly.

So if you also want to fix this error yourself, just follow this detailed guide.
Now let’s dive right in…
First, let’s face all the steps.
- Log into cPanel
- Verify Database Information in wp-config.php
- Check Database Credentials in cPanel
- Refresh the Site
- Fix 404 Errors in WordPress Dashboard
Ok, now let’s jump into a detailed explanation of every step.
Wait, first, you should know why this error happens.
It is a general problem that comes when WordPress is unable to find proper access to the database. And now I’m going to walk you through the steps to solve it so your site will be running efficiently once more.
Speaking of…
Step 1: Log into cPanel
To solve this problem, first sign into your cPanel. After logging into the control panel, you will be directed to the cPanel; now click on File Manager.

Then search for the folder labeled public_html. Where all your WordPress files are stored.

We will concentrate on the wp-config.php file, as it holds the WordPress database connection details.

Move on to…
Step 2: Check Database Details in wp-config.php
In the wp-config.php file, you will find
- Database name
- Username
- Password

In other words, if any of this information is incorrect or doesn’t match what is stored in actual database credentials, WordPress will not be able to connect and the error will be coming.
Time to explain…
Step 3: Check Your Database info on cPanel
To ensure the credentials in wp-config.php are correct, follow these steps:
- Return to the cPanel and look for the database link.

- After clicking on it, you can see your database name,

Username and password.

- All this has to be compared with the one in the file known as wp-config.php.

- If the database name, username, or password doesn’t match, then change it in the WP-CONFIG.PHP file. Just you can copy and paste it into the wp-config.php file in the exact place.
- If required, reset the database password in the backend from cPanel; after that update the same password in wp-config.php and finally save the changes.
Jump to…
Step 4: Refresh the Site
After you update your credentials, save the changes in the wp-config.php file and refresh your site. If the database information was the problem then your site should open perfectly as it is right now.

Step 5: Fix 404 Errors in WordPress Dashboard
There is no known method to prevent 404 errors from happening.

So the next best thing to do is to fix those errors in the WordPress dashboard.
At other times, after rectifying the database connection error, you can still see some 404 errors on the sites. To resolve this:
- First, you need to log into your WordPress dashboard.
- Click on Settings in the WordPress Administration toolbar, then click on Permalinks.

- Just click on Save Changes leaving all the options in default settings.

By doing this it will replace the current permalink structure and should eliminate all the 404 errors.
Test Your Site
Visit various pages to ensure everything is loading correctly.

Now It's Your Turn To Take Step
I hope this guide has shown you how to fix error establishing a database connection in WordPress.
Now I’d like to hear from you.
Did I miss anything that you think should have been written?
Did you understand step 4?
Or do you have a question about something you read?
If you’re still facing issues, feel free to contact me! And I’ll be glad to assist you.
1 thought on “How to Fix Error Establishing a Database Connection (Complete Guide)”
To get instant help, DM me on WhatsApp.