Get fresh WordPress Content delivered in your inbox with warpspeed!

learn wordpress wplift wordpress rocket

Are you freaking out about that giant “Error Establishing a Database Connection” message that shows up when you try to access your WordPress site? A bug that crashes your entire site is every WordPress website owner’s worst nightmare, that’s for sure.

But while this specific error is drastic in its results (your whole site appears to be gone!), it’s usually not so difficult to fix.

Before I dig into how to fix the Error Establishing a Database Connection message, I just want to reassure you that, barring something really bad, all of your site’s data should be safe and sound. So don’t start freaking out too much!

Alright, with that little pep talk out of the way, let’s dig into what this error means, why it happens, and how you can go about fixing it on your WordPress site.

error establishing a database connection message

What Does Error Establishing a Database Connection Mean?

Ok, before I show you some ways to troubleshoot this error, I think it’s important that you actually understand the mechanisms underlying why you’re seeing the error message.

There are two core parts to WordPress:

  • The actual HTML/PHP - this is what controls how your site looks and functions.
  • Your database - this is what actually stores all of the information for your posts, pages, settings, users, and more.

When a user lands on your site, the HTML/PHP part of WordPress queries your database to actually get the content to insert into the framework constructed by the HTML/PHP (caching plugins change this a bit...but that’s beyond the point).

In order for WordPress to successfully query the database, it needs to...establish a connection to the database.

Without a connection, WordPress can’t access any of the content it needs to serve up to your visitors. So if WordPress is unable to establish a connection to the database specified in your wp-config.php file, it gives you this error.

What Causes The Error Establishing a Database Connection Message?

Now that we’ve established the meaning behind the message, let’s start digging into why it’s actually showing up on your site.

If you’re installing a brand new WordPress site, you probably just incorrectly entered the database credentials.

But if you’re seeing the error on an established WordPress site, there are some other possible culprits:

  • Your database is corrupted. Sometimes WordPress will throw this error if your database is corrupted. I’ll show you how to check for this in a second.
  • Your login credentials are wrong. If you recently changed your database credentials, you’ll get this error if you forgot to add those new credentials to your wp-config.php file. You could also be having issues with proper permissions related to your database username.
  • You’re having a problem with hosting. There are a couple possible issues that I’ll cover.

Keep reading to learn how to fix each specific problem.

How to Fix a Corrupt WordPress Database

Thankfully, there’s a simple trick to tell if a corrupt WordPress database is causing your woes:

Try logging into your wp-admin dashboard.

If the error message changes to something like “One or more database tables are unavailable. The database may need to be repaired”, you’re in luck!

That means it’s actually a corrupted database, rather than a ruptured database connection. On the other hand, if the error message doesn’t change, you should just go ahead and skip to the next section.

To fix your corrupted database, you’ll need to do two things:

  • Add a code snippet to your wp-config.php to enable the repair tool.
  • Run the repair tool.

First, use an FTP program or cPanel’s File Manager to edit your wp-config.php. I think File Manager is the simplest, so that’s what I’ll use for this guide.

To access File Manager, look for the File Manager icon in cPanel, then choose the site that’s being affected by the error.

Then, just click on wp-config.php and choose the Edit option:

And paste in this line of code at the bottom:

define('WP_ALLOW_REPAIR', true);

Then, head to:

yourdomain.com/wp-admin/maint/repair.php

And click on the Repair Database button. WordPress will take over from there and, hopefully, return your site to a working state.

Once you run the repair process, make sure to go back to your wp-config.php file and delete the line of code that you added. You shouldn’t leave the repair function enabled all of the time.

How to Fix Incorrect Login Credentials

There are two potential reasons the login credentials in your wp-config.php file aren’t working:

  • The details are just plain wrong. That is, the database name, username, and/or password aren’t correct.
  • The database user doesn’t have access to the database with the required privileges.

While it’s possible to troubleshoot individual elements of your database credentials...I think the easiest way is to just create a completely new user. That way, you can be 100% sure everything is accurate.

To do that, head to MySQL Databases inside your cPanel dashboard:

Scroll down and Add a New User:

Once you do that, scroll a bit further and add that new user to your existing WordPress database using the Add a User to a Database option:

On the next screen, make sure to check the All Privileges box:

Then, update your wp-config.php file with the new database user and password. You can use the same File Manager method I outlined above to do this.

When you save your wp-config.php file, you can be absolutely sure that your credentials are correct. And hopefully, that solves the error for you!

Still Not Working? Talk To Your Host

One possible, but unlikely, potential hosting issue is that your host uses separate servers to host databases. If the database server is down, your site will still load even though it can’t access the database...causing the error that you see.

But a more likely hosting culprit is that you just flat out are running out of resources. Specifically, your server’s memory limit is too low. Commonly found on budget shared hosts, low memory limits can cause your WordPress site to throw database errors.

To fix the issue, you can try talking to your host’s support about increasing the site’s memory limit. Or, you might just need to upgrade to better WordPress hosting.

Wrapping Things Up

In the vast majority of cases, fixing one of these issues should get your site reconnected to the database and working properly. While there are always potential outliers, it’s more likely you simply made a typo while inputting your database credentials, installed a plugin that corrupted your database, or are having some hosting issues.

If you’re still running into issues, though, leave a comment and I’ll do my best to help out.

Published:

Last updated on:

Colin Newcomer is a freelance writer and long-time Internet marketer. He specializes in digital marketing, WordPress and B2B writing. He lives a life of danger, riding a scooter through the chaos of Hanoi. You can also follow his travel blog.

Join 40,000 WordPress Astronauts
AND GET OUR LATEST CONTENT IN YOUR INBOX WITH WARPSPEED

We will never spam you.
close-link
siteground coupon
Get 60% Off the No. 1 WordPress Hosting!
Get 60% Off the No. 1 WordPress Hosting!