WordPress Tutorials » Optimization » How to Fix the Error Establishing a Database Connection in WordPress

How to Fix the Error Establishing a Database Connection in WordPress

Optimization, WordPress Tutorials

The following tutorial provides detailed information about the Error Establishing a Database Connection message in WordPress, including meaning and a few possible methods to fix it.


What Does the Error Mean?


If you are a website administrator and own a WordPress Hosting account, you have probably come across the Error Establishing a Database Connection error at some point. The message itself is a bit generic and does not give enough information about the root cause of the problem. However, what it means is that WordPress is encountering a problem while attempting to connect to its associated database.

The image illustrated below will give you a better idea and understanding of the warning.

error establishing a database connection in wordpress  

Below, we’ve compiled a list of known solutions to the database connection issue that every WordPress administrator and end-user may encounter.


Solution #1: Check the wp-config.php file


If you have recently performed changes to your MySQL database via your Database Manager (such as modifying the password of your database) or your hosting account has been moved to a different server, then you will need to update the file wp-config.php as well.

wp-config.php (also known as the main configuration file) is probably the most important file in every WordPress system. It stores essential and sensitive information regarding your blog, such as the database connection settings and the security keys.

error establishing a database connection in wordpress 2

Open up the configuration file (it should be located in the root directory of your domain/sub-domain name). Once in the editor, look for the following four variables in your PHP code:

  • define('DB_NAME')
  • define('DB_USER')
  • define('DB_PASSWORD')
  • define('DB_HOST')

Double-check all four variables defined in the code and ensure that they match the database settings available in your Database Manager.

error establishing a database connection in wordpress 3  

Solution #2: Repair the database


There are times when a database may become corrupt or damaged. Database corruption usually occurs as a result of a faulty or badly configured WordPress theme or plugin.

If you happen to receive an Error Establishing a Database Connection error, you can try to resolve the issue by repairing the MySQL database associated with your WordPress instance.

Performing a database repair is seamlessly easy and can be done in four steps:

  1. Sign in to your AwardSpace account.
  2. Once logged in, navigate to the MySQL Manager page inside your dashboard.
  3. Locate the database that is linked to your WordPress site and click on the Options icon.
  4. Open the Management tab and press the 1-click Repair button.

error establishing a database connection in wordpress 4  

Now that you’ve followed the above steps, it is time for you to test your WordPress site’s connectivity. If everything goes as planned, no further error messages should appear on your page and your website should display properly.

AwardSpace on Social Media

Choose the Right Hosting

Prices starting at 0.90€1.08€$0.90$1.08/year!

Share This

Share This

Share this post with your friends!