Ultimate Guide: How to Fix Database Connection Error in WordPress

By | September 8, 2017

Database-Connection-ErrorEvery WordPress website owner understands the importance of the WordPress database. Your content, user information, settings, images, meta descriptions, etc, all fall within your website database. WordPress websites run smoothly at most of the times. But, on some occasions, you face unexpected problems among which “error establishing a database connection” is the most frustrating ones.

Because of this problem, your website remains offline and visitors can’t access them. It causes a great loss to your web-based business in terms of traffic, leads, sales, etc. So, how you can solve this problem and make your site live once again? There are many scenarios that cause this error. Just have a look at those situations and their easy solutions, compiled here below:

1. Incorrect Login Details

Generally, you don’t face this problem If you install WordPress using your hosting company’s one-click installer. But, if you create a WordPress site/blog yourself and forget your login details by mistake, then you come across this trouble. If you have updated your login credentials recently, you won’t be able to access the admin panel of your website if you use the old login details.

Solution:

A. Find the Correct Login Details:

First of all, you should try to locate the correct login details which include Database name, Database host, Database username, Database password. You can easily find these details in your cPanel under MySQL Databases.

Here, you can find a list of Database installations and database users.

B. Scrutinize Your Database Credentials:

In the second step, you need to download or open wp-config.php file. To perform this action, you can use an FTP. Alternately, Go to your sign into your cPanel- open your file manager-choose the “Web Root (public_html/www)” and click “Go”.

Now, choose the wp-config.php file and click on the “Edit” option. Just scroll down some lines and you will get the required information easily.

If you fail to recover your login details, just select the user and reset the password. Insert the new password in your wp-config.php file.

You can create a new user and add them to your site’s database. For this, you need to have multiple database installations so that you choose the correct database after checking all of them.

C. Inspect Your Table Prefix:

You will not be able to find your login credentials if you are wading through the wrong database. So, when you look around your wp_config.php, just ensure that your table prefix is correct.

2. Corrupted Database

Data-transfer interruptions, flawed plugins, add-ons, themes, etc, can corrupt your database completely and create the database connection error. When your website has corrupted database, its front-end may seem to work as usual, but the back-end area shows the error message clearly.

Solution:

A. Repair the WordPress Database:

Just open your wp-config.php file using the editor, go to the bottom of the file and add the below-mentioned code:

Now, save the changes you have made. Open a new tab in your browser and visit the following URL:

Here you access the WordPress database tool. You can choose either “Repair Database” or “Repair and Optimize Database”. As soon as you finish this step, rerun to your file editor, erase the line that you added at the bottom and save the file once again. This will disable the repair tool.

B. Database Repairing with phpMyAdmin:

You can also repair your database tables using the phpMyAdmin interface in your cPanel. Use this method carefully because even a single mistake can erase your database from within phpMyAdmin. Before making any change in your database, please take its backup.

Open the phpMyAdmin- choose the right database on the left side of your screen – select the structure tab- highlight all the tables- Repair table with the help of the drop-down box.

As soon as you complete this step, close the phpMyAdmin and check your site.

3. Problem with Site’s Server

You may come across the database connection error if there is a problem with your site’s server. These days, most of the individuals use the shared hosting services to run their websites as they are cheap and affordable. But, Shared Web Hosting has several disadvantages too.

When a website (hosted on a shared server) is hacked by hackers, other websites on the server may feel the same problem. Sometimes, the problem is caused by an overloaded server. You can ask the hosting company to fix the issue ASAP or can change your hosting company.

Final Words:

Database connection error in WordPress disturbs your day-to-day activities of your web portal and ruins your visitors, leads, and reputation. You can easily solve this problem by using the above-mentioned tips.

Author Bio:

Brandon Graves is a WordPress website expert. He has a great passion for providing easy tips to solve WordPress errors, and perform the wordpress web design services. To get frequent updates from him, follow him on Google Plus.