Disclosure: Aussie Hosting is community-run. We sometimes earn a commission when you buy hosting through our links. Learn more.

Error Establishing a Database Connection

Nathan Finch——Last Updated on August 25, 2021

WordPress is one of the best platforms for establishing your own online business or blog, but it does have its fair share of potential technical issues. For example, many people eventually encounter an “Error Establishing a Database Connection” message at one time or another.

Unfortunately, it can be tough to know what this error message means, let alone how to fix it.

Luckily, there are ways to fix such an error message. Even better, the root cause of the error message is usually not a big deal, even though it could be due to several different problems.

Read on for five ways to fix “Error Establishing a Database Connection” messages on WordPress.

Table of Contents

What Does Error Establishing a Database Connection Mean? What Causes It?

questionThe heart of fixing any type of technical issue, including an Error Establishing a Database Connection message, lies in understanding where it comes from.

Basically, WordPress uses two key pieces of technology, PHP and MySQL, to work as flexibly as it does. PHP is a programming language and all core WordPress files are written in it. MySQL, on the other hand, is WordPress’s database technology.

It stores all the content on your website, including your posts and pages, your color settings, and even your widgets.

Normally, WordPress uses PHP commands to connect to stored information on the MySQL database. Then, once it retrieves the information, it displays that info on your screen.

But when you get an Error Establishing a Database Connection message, it means WordPress can’t get the information it needs from the database through its PHP script. It’s basically WordPress saying it doesn’t know what to do since it can’t get the database information it normally uses.

So, what causes this type of error? It could be any number of things, including:

  • ☑️ You may have incorrect login credentials. Whatever WordPress accesses your database, it needs specific login and password information. If it doesn’t have that, it can’t get information from the database
  • ☑️ The WordPress files may also be corrupted. This can occur when WordPress updates improperly, when you have certain themes or plugins that don’t update, or for a variety of other reasons
  • ☑️ The database can also be corrupted, which may occur when you have a plugin that messes with the database information or a hacker attack. But it can also be something as basic as a theme not working
  • ☑️ The database server may be down, in which case the server storing your database information is simply not working at the time
  • ☑️ Your WordPress site may also have too much traffic. While this may be a good thing in theory, it could cause your database to be unresponsive, leading to a crash and an "Error Establishing a Database Connection” message

Fortunately, no matter which issue is the root cause of your error, there are ways to fix the problem without needing to hire a tech expert. 


1. Talk To You Hosting Provider About Database Host Info

customer supportFirst and foremost, contact your WordPress hosting provider ASAP. As seen above, one of the primary causes of an error code like this is because your database server has crashed.

By contacting your WordPress hosting service, you can double-check that your database server is up and running and isn’t experiencing any problems.

Furthermore, the WordPress hosting provider you are subscribed to can tell you if there is a sudden spike in activity or traffic on your website.

If there is something wrong with the server, they could dig deeper into the issue and discovers the fault is on their end, it’s the fault is on your end, or if there is a malicious actor causing the problem not just for you but for other WordPress sites.

Of course, if your WordPress database server is down, there’s nothing you can do except wait for your hosting provider to get the server back up and running. This is just one big reason why it’s important to choose a hosting provider with as much uptime as possible.

If it’s not your WordPress database, however, you need to move on to another potential solution.


2. Check and Fix WordPress Database Credentials

licenseThe easiest way to fix the above error message is to check and fix damaged WordPress database credentials.

The database credentials can become damaged for a number of reasons, but moving your WordPress site to a new host is by far the most common.

In any event, you need to visit the wp-config.php file to do this. Access this by downloading FileZilla and using FTP to reach the server.

Once you’re in the correct folder, look for lines like define ( ‘DB_Name’, ‘database_name_here’ ), and so on.

The goal is to make sure that all the information under those "define" lines of code is accurate, including the database name, username, password, and your database host.

To make sure they are accurate, just check your WordPress hosting account dashboard. If the information is false, change it so it is accurate and see if you still have the error message.


3. Repair Your WordPress Database

If the above tactic didn’t work, you can repair your WordPress database, particularly if you see a message like “one or more database tables are unavailable”. This may indicate that your database has to be repaired.

repair database

Go back to the wp-config.php file and find the “That’s all, stop editing! Happy blogging” line in the file. Just before, add the following text:

  • define( ‘WP_ALLOW_REPAIR’ , true);

Once you’ve done that, repairs should begin and you can see your settings by visiting repair


4. Make Sure No Theme/Plugin Files Are Corrupted

404 not foundIf all the above tactics haven’t worked, make sure that no theme or plugin files are corrupted. WordPress files can be corrupted for all kinds of reasons, such as a bad update or not updating your plugins or themes properly.

Many WordPress site owners find that once they update a particular plugin or theme, they run into technical problems. You can also accidentally cause this error if you hand edit some of your files.

In any case, connect your host via FTP using tools like FileZilla, which are totally free. Go to the emails you received from your web hosting provider when you first signed up for their service to discover your login and password information for your FTP account.

Then connect to your server and navigate to your WordPress root folder. It’ll probably be named something like “wp-content”.

Once there, rename the “plugins” folder to something else that you’ll remember. Go back to your website and see if you are still encountering the error. If you are not, you know the problem is with a plugin. Then you can go back and reinstall your plugins one by one.

You can use the exact same tactic to discover if a theme is the culprit behind your error message.


5. Restore WordPress to Default

wordpress packageIf all the other strategies above didn’t work, you can always go nuclear and restore your WordPress files to their default versions.

This may be your only option if your core WordPress files are corrupted beyond your ability to rewrite, especially in the event of a hacking attempt or if a file modification experiment went wrong.

Fortunately, this is pretty easy. Just visit WordPress.org and download a clean version of the WordPress files, then copy them over the files you have installed right now. To do this:

  • Download the newest WordPress package to your desktop and unpack it
  • Then browse through the unpacked file archive. Delete the “wp-content” folder. Doing this will ensure that WordPress overwrites all of its files except the content specific to your site
  • Use FTP to connect to your site and go to your main WordPress root file as described above. Then upload the new WordPress files
  • When prompted, click “yes” to overwrite all of the files except for your content files
  • Now go back to your website and see what has happened

Of course, this path should only be followed as a method of last resort. You should also back up all of the content on your WordPress site if possible beforehand in case it goes wrong. The last thing you want to do is wipe away all the content on your site and have to redo it and re-upload it, particularly if you have an extensive blog or an online store.


Wrap Up

Hopefully, one of the above methods will allow you to fix an “Error Establishing a Database Connection” message if you see it pop up. This problem is unfortunately quite common for WordPress users, but most of the time it’s fixable with at least one of the above workarounds.

Still have more questions? Don’t hesitate to contact customer support at WordPress for more information or to get some in-depth technical support. When in doubt, they may be able to point you in the right direction or figure out what’s wrong with your site. Good luck!

You Might Also Like: