Choose another country or region to see content specific to your location and shop online.
United States
USA

How To Fix Error Establishing A Database Connection In WordPress

When you start using WordPress, you’re facing a number of errors, some grievous, other not so much. it can be your fault, at times systems break, someone fails at their job, natural calamities strike – anything could cause an error.

Now, just like any other human-made project, WordPress is susceptible to its share of errors, none of which is as baffling and strenuous as the “error establishing database connection” error. That’s because this error doesn’t come with details of what went wrong, despite that it can be caused by several things, which – of course – only adds salt to the wound.

All you get when you try loading your site is:

What Does “Error Establishing a Database Connection” mean?

WordPress is built using PHP (e.g. index.php, sidebar.php etc) and MySQL. PHP is in charge of all functions on your WordPress site (e.g. posting comments, retriving posts and pages etc) and MySQL is in charge of data storage.

For instance, when you type your URL in the address bar and hit enter, PHP kicks in, fetches and displays the contents of the homepage (index.php) from your MySQL database. Images, videos and such media are, however, stored in the wp-content folder, from where they’re retrieved by PHP.

Your MySQL database contains all the vital information PHP needs to create your site. Now, when PHP can’t access your MySQL database for one reason or another, you get the dismaying “error establishing database connection” message on your screen. Which is just PHP-speak for I couldn’t find the data I needed to put together you WordPress site. Here’s an error to show you I tried.

This error can be caused by a number of reasons including but not limited to:

  • Incorrect login details; typos, wrong quotes and extraneous spaces – Changes to your database login details can “block” your website from accessing the database.
  • Unresponsive database server – The server where your database lives could be as dead as a dodo; caput, unresponsive or still recovering from a traffic upsurge.
  • Corrupted WordPress files
  • A corrupted database – Bad plugins, addons, themes and data-transfer interruptions might leave your database short of tables or completely corrupted at worst.

Troubleshooting “Error Establishing Database Connection.”

we would be insane if we tried to fix the problem without first establishing the cause. If we can determine the root of our error, then getting a viable solution is a matter of when.

Is Your WordPress Database Corrupted?

We can start by checking whether the error is as a result of a corrupted database. For this, we have to test if the error has crippled the back-end as well.

All you have to do is navigate to yoursite.com/wp-admin/. Please don’t forget to replace yoursite.com with your own domain name.

If loading the front-end (i.e. yoursite.com) and the back-end (i.e.  yoursite.com/wp-admin/) results in the “EEDC” error, your database is fit as a fiddle, and you needn’t concern yourself with the next step. You can skip all the way to determining whether you have the correct login credentials in your wp-config.php file.

However, if you’re getting “One or more database tables are unavailable…” or something else but the infamous “EEDC” error, your database is corrupted and in die need of repairs.

Don’t worry one bit though, as repairing your WordPress database is easy peasy work. You can be done in three simple steps. Firstly, locate the wp-config.php file, which lives in your WordPress root directory. The root directory is the folder where your WordPress site is installed.

You can usually find this folder inside the default home folder or “public_html”. Just login to your cPanel, and navigate to File Manager.

Then navigate to your WordPress root folder:

From this point, locating your wp-config.php file should be easy:

Once you have access to wp-config.php, open it in editing mode. Right click on the file to choose the code editor, or select code editor in the menu:

This will open your wp-config.php in a new tab. Add the following code at the bottom:

define ( 'WP_ALLOW_REPAIR' , true);

Save your changes.

The above code allows you to repair your WordPress database without having to login into phpMyAdmin manually, which might be quite a tussle depending on your experience.

The second step involves navigating to yoursite.com/wp-admin/maint/repair.php. This should open the following screen:

Third step, just choose either “Repair Database” or “Repair and Optimize Database” and let WordPress do the rest.

NB: Once your database is repaired, remember to delete the code you added to your wp-config.php file. Otherwise, you risk granting hackers access to your database, where they will wreck havoc.

If repairing your database solved the error, well and good, just go ahead and pop the bubbly. If you’re still seeing the error after repairing the database, perhaps the error stems from incorrect login details, corrupted WordPress files or an unresponsive database server.

Let’s check whether your database login details are the problem.

Checking Your Database Login Credentials

Open your wp-config.php once again and look for the following lines of code:

/** The name of the database for WordPress */

define(‘DB_NAME’, ‘database_name’);

/* MySQL database username */

define(‘DB_USER’, ‘database_user’);

/* MySQL database password */

define(‘DB_PASSWORD’, ‘database_password’);

/* MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

The details in the second pair of parentheses, where we have ‘database_name’, ‘database_user’ etc, will not appear as shown in the code above. These details are specific to your website and host.

The four lines simply mean:

  • ‘database_name’ – The name of your database goes here e.g. ‘wordpress_vista’
  • ‘database_user’ – Your database username goes here e.g. ‘wordpress_new’
  • ‘database_password’ – This where you put your password e.g. ‘test!@#!@#’
  • ‘localhost’ – This is where you input your database host. The default is ‘localhost’ for most web hosts.

If any of these four credentials are incorrect, you will get the “error establishing database connection” error.

New customer

New to ELITEWEB.Co? Create an account to get started today.

Registered users

Have an account? Sign in now.

Reseller login

If you’re a reseller, use the button below to sign in. (your reseller account is separate to your regular account)

Reseller login

If you’re a reseller, use the button below to sign in. (your reseller account is separate to your regular account)

New customer

New to ELITEWEB.Co? Create an account to get started today.

Registered users

Have an account? Sign in now.