fbpx

Fix Error Establishing Database Connection WordPress

THIS POST MAY CONTAIN AFFILIATE LINKS. PLEASE READ MY DISCLAIMER FOR MORE INFO.

This is a very common WordPress error message. In this article I will address the three main causes and how to resolve each of them.

  1. Incorrect Database Login Credentials
  2. Database is Corrupted
  3. Hosting Issue and the Database Server is Down

What is the Error Establishing a Database Connection?

WordPress is dependent on a database. All the content, pages, posts, plugin settings, theme settings, everything, is stored in the database.

This is why the entire page is blank, no data can be retrieved to display the page because the connection is not working properly. Not only does this break the frontend of your site, but it will also prevent you from logging into your WordPress dashboard.

Let get to work!

1. Database login credentials are incorrect

This is probably the most common cause of the three I will discuss here.

WordPress has a file titled, wp-config.php, in this file (among other things) are the configuration settings for connecting to the database. It looks something like this.

WordPress database connection strings

In most cases, when I’m fixing this error, it is because someone changed their database password thinking they were changing their WordPress admin login.

Here’s how to fix it.

Step 1. From the wp-config.php file pictured above, you will want to copy the “DB_PASSWORD, which in this example would be “root”.

Step 2. Login to your hosting account and update the password for the database named in your wp-config.php file. Below I have pictured how to do this for three common hosting types, cPanel, WP Engine, and GoDaddy Managed WordPress.

cPanel:

Once in the cPanel, you’re looking for the MySQL Databases icon as pictured below.

After clicking on the MySQL icon, you will see page with options for creating a database, viewing your active databases and all the way at the bottom of the page you’ll see the “Add User to Database” section as pictured below. We’re going to edit the user password so you’re looking for the “Current Users” section to complete steps 1 and 2 below.

  1. Locate your database user name. You can find the correct user by looking in the wp-config.php file pictured above.
  2. Click on “Change Password”

After clicking on “Change Password” you will see an option to create a new password.

  1. Copy and Past the password we looked up in the wp-config.php file into the two password fields.
  2. Click “Change Password”

After completing these steps, check your website. If the site loads, you’ve solved the problem

WP Engine

This one is a little unique. You, as the end user, can not change the database password, so unless you messed with your wp-config.php file, it’s unlikely that this is the issue. However I have outlined the steps for getting the password reset.

  1. Login in to my.wpengine.com
  2. Click on the “Live Chat” option at the top right of the screen as pictured below.

Once you’ve done that, just follow the pomps and once an agent is available let them know you’d like to reset your database password. They will do all the work form there!

GoDaddy Managed WordPress Hosting

This one is like WP Engine, you the end user, can not change the password. You would have to called support and request that they change the password for you. However, the steps below show you where to find your password to confirm that it is correct in your wp-config.php file.

  1. Click on “Settings”

  1. Scroll to the bottom right of the screen to see Database section, then click on “View”.

  1. In the popup window, click on “Toggle Password” to see your actual password.

After completing these steps, check your website. If the site loads, you’ve solved the problem! If not you’ll want to move onto one of the other two troubleshooting techniques.

2. Your database is corrupted

When you try to logging in to your WordPress dashboard and see the following error, it means your database is corrupt.

One or more database tables are unavailable. The database may need to be repaired.

Keep in mind, you might only see this error when trying to login to the WP Admin, but you will still see the error establishing a database connection message on the frontend.

Fortunately, WordPress has a database repair mode which you can activate and run.

Just add the following line of code to the bottom of your wp-config.php file and save it.

define('WP_ALLOW_REPAIR', true);

Next step is to visit the following URL in a browser (replace yourdomain.com with your website address), http://yourdomain.com/wp-admin/maint/repair.php.

You will have two options, 1. repair the database or 2. repair and optimize the database.

For now let’s just repair the database. We can always optimize it later (which is a good thing to do from time to time).

Your will see something similar to this once the repair is complete.

After the repair completes, check your website by going to the homepage and logging into the WP Admin. If the errors are gone then you’ve solved the problem!

Don’t forget to remove the code you added to the wp-config.php file.

3. Issues with your database server

If you’ve complete options 1 and 2 above and still having issues. I would recommend that you try and login to phpMyAdmin. If you get a login error, you should call your Hosting Provider.

In most cases, logging into phpMyAdmin is going to be automatic, just by clicking on the phpMyAdmin link or icon should try to log you in directly to phpMyAdmin.

Here is what that looks like in cPanel and WP Engine.

WP Engine Dashboard

cPanel

Wrapping Up

If you’ve gone through all of this, but still struggling with the Error Establishing Database Connection, there are other things you can try, I’m not listing them in this article because they’re not very common and usually not the cause.

A couple of those other issues could be:

If you need more help in resolving this issue please order a One Time Fix here!

As always, if you have any questions, please use the comments below and I’ll do what I can to assist.

Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.