Are you facing the “Establishing a Database Connection in WordPress” error on your website? This means your database is unaccessible. Maybe your database server is down or the credential of your database are wrong on the wp-config.php file on your WordPress website. The “wp-config.php” file is a file where your database credential is stored. To fix this error, please follow all of the steps mentioned below.
Check Your Database Credential:
A database is a software where all the data of your website are stored. If WordPress fails to connect with the database server, you will see the error “Error Establishing a Database Connection in WordPress”. So if you see this error the first thing you need to do is to check the credential of your database from your “wp-config.php” file. The “wp-config.php” file is located on the root folder of your website.
In this step, you need to open the “wp-config.php” file and check carefully if the credential of your database is correct. Now maybe the question is how do you understand if the database credential is correct or not?
Well, Go to your cPanel and search for “MySQL Databases”. Depending on the hosting provider, the cPanel might be different. You need to find the database from your cPanel and check the Database Name, Database User, Database Password as well as the Database host. Here if you see the database credential is the same as “wp-config.php” of your website, then the problem is not here.
Repair WordPress Database:
If you see one or more database tables are unavailable. The database may need to be repaired.
By adding the above code to your “wp-config.php” file, you can repair your database. But make sure to add this code just before of the line “‘That’s all, stop editing! Happy blogging’”. To see the setting of the auto database table repair option, you need to go through http://www.yoursite.com/wp-admin/maint/repair.php | Please make sure to replace yoursite.com with your domain.
Note: Click the “Repair Database” button to repair your database automatically.
Check Your Database Host Information:
If you are pretty confident that database name, database username, and password information is correct, then the “host” information of your database may be wrong. Now you want to make sure the host information is correct. To verify the host information, please contact your hosting provider.
Besides here are a few small tips I want to mention that is: 90% of hosting companies use localhost as their database host. Anyway, some managed WordPress hosting companies use separate servers to host their databases. In this case, your database host information will be different. So, you need to contact your hosting provider to know about the host information.
Your Database Server May Down:
The database server of your hosting provider may down for many reasons. In this case, you need to make sure by contacting to their support center if the database server is running correctly or not.
N.B. This is a developer-level tutorial. If you felt, it’s difficult to do for you. You may consider hiring me through Fiverr. I’ll fix your issue as soon as possible.