How to Fix WordPress Database Connection Error ?

database connection error
How to Fix WordPress Database Connection Error?

Looking at the error “Error Establishing a Database Connection” in WordPress can be hopeless. This problem prevents your website from loading, stops your website from loading, and harms SEO and traffic. Thankfully, you can fix it quickly by following the correct steps. Let's go through each one. In this blog, we will learn how to fix WordPress database connection error.

Step 1: Examine Your Database Credentials

First, ensure your database details are in the wp-config.php file. These include:

  • Database name
  • Username
  • Password
  • Host (usually localhost)

Log in to your hosting control panel, examine it, then open File Manager, and discover wp-config.php in your WordPress root directory. Confirm the information is the same as in your hosting account’s database section.

If they aren't the same, re-create database credentials and save the file with the correct details.

Step 2: Repair the WordPress Database

Sometimes, there is a fault in the database. In this condition, WordPress can try to correct it.

Include the following line in your wp-config.php file just before the line that says 

  • Stop editing!:
define('WP_ALLOW_REPAIR', true);
  • Next, go to: yourdomain.com/wp-admin/maint/repair.php

Click on “Repair Database.” After the process is perfect, delete the line you were involved in wp-config.php. 

Step 3: Check Your Web Hosting Server

If the issue persists, your server may go down. For examination, use these tools, such as www.isitdownrightnow.com. Open this website and copy/paste your website URL in the text field and hit the 'Search' button.

If the report says 'UP' status like yoursite.com is UP and reachable by us, then it confirms your server is working fine, otherwise, there will be a problem with the server if the report status is not 'UP'.

Step 4: Update WordPress URL in phpMyAdmin

The wrong URL of the site can also generate this problem. Move to your hosting panel approach. Go to your hosting panel, access phpMyAdmin, and choose your WordPress database. Click on the wp_options series. Look at the “siteurl” and “home” rows. Confirm they are the same domain (e.g., https://yourwebsite.com).

Step 5: Restore a Backup (If Needed)

In your phpMyAdmin, select the desired database name. Import your Database backup using a file named ".sql", from a backup, then refresh your website if it does not work. Some hosting suppliers grant automatic backups.

You can also read our post on 404 Errors on WordPress Posts that often come up in similar situations.

 

Summary

This error can be puzzling, but with smooth access, you can fix it rapidly. Always examine again and again, and do not feel any confusion about contacting support. In WordPress, you have information on how to fix the error establishing a database connection. Take action and start running your website.

Related Solutions