Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Error Establishing DataBase Connection - WordPress fixes

Error Establishing DataBase Connection - WordPress fixes

Did you recently receive  Error Establishing DataBase Connection ? No worries.It’s something usual for WordPress. In this article we will be showing you how to get rid of Error Establishing DataBase Connection – WordPress fixes.

Before we start we would like to ask if you are happy with your web host ? If not , then we suggest you taking a look into this (Best Web Hosts included)

What are database connection errors in WordPress

As far as website errors go, this one is pretty easy to recognize. You’re told exactly what’s wrong, without convoluted HTTP error codes :

Fixing an error establishing a database connection.

While we know what the error entails, the problem is that there are a lot of things potentially preventing you from establishing a connection with your database.

Your database stores your site’s information. Without access to it, your site is crippled, so we want to troubleshoot this error fast, then keep it maintained in the future.

Four steps to fix the Error establishing a database connection in WordPress warning

In very few cases, WordPress might not be able to establish a connection to the database due to incorrect credentials. If everything else fails, you can check if your credentials are set correctly.

Additionally, it’s possible that your WordPress host is experiencing issues. Some WordPress hosting providers host databases on a separate server from the rest of your site. If the database server goes down, that can also trigger the warning.

With those caveats out of the way, let’s dig into four ways to troubleshoot the Error establishing a database connection warning in WordPress.

1. Restore a recent backup that includes your database

In short, you should have a recent backup of your website available at all times. This backup should also include a copy of your database, so you can restore the entire website to a working state before the connection error.

Restoring a backup without access to the WordPress admin can be tricky though. In fact, if you depend on a plugin solution, you might be out of luck altogether.

Ideally, you’d have already set up automatic backups with your web host – and you can usually restore them from your control panel:

Restore WordPress from Backup - cPanel Control Panel

If this applies to you, fixing the error establishing a database connection in WordPress is a matter of simply choosing which backup to use.

On the other hand, if you only have access to manual backup files, you may need to upload them manually. This means both uploading your WordPress files and using a tool such as phpMyAdmin to restore a database backup.

2. Check for corrupted WordPress theme and plugin files

In some cases, compatibility issues between plugins, themes, or corrupted files can prevent WordPress from establishing a connection to the database. Usually, this can happen right after you update a theme or a plugin, which points to one of those files as the culprit.

However, you might be thwarted by a lack of access to the dashboard. This means you need to rule out plugins and themes by disabling them using FTP. Given this, you’ll need to use a client (such as FileZilla) to access your website.

Go ahead and connect to your site via FTP, then navigate to the wp-content directory. Inside, you’ll find at least two folders:

  • plugins
  • themes

First, you should rule out plugins as the culprit. To do so, rename the plugins folder to something else, such as plugins.disabled. This change will automatically disable all of your active plugins.

Manually disabling plugins to fix the error establishing a database connection in WordPress

Now try accessing your website to check if the error persists. If it’s gone, it means one of your active plugins was the culprit.

To find out which one, return the plugins folder to its original name and head inside. Now, work your way through each individual plugin folder, changing its name each time, then checking to see if the error goes away.

Keep disabling plugins one by one until you land on the one wreaking havoc. If none of your plugins are causing problems, its time to turn towards your active theme.

The process here works just the same as with plugins. Navigate to the wp-content/themes directory and look for the folder that corresponds to your active theme:

The themes folder within FileZilla.

Go ahead and change the folder’s name to anything else. Doing so will cause WordPress to revert to one of its default themes, which will affect the way your site looks. Don’t panic, though – if your website is now loading fine, we can fix the problem by reinstalling the theme in question.

3. Reinstall WordPress core files

So far, we’ve ruled out plugins and themes as the from being behind the error establishing a database connection in WordPress. Now, let’s check if some of your WordPress core files are the ones causing problems.

The simplest way to fix this is to replace all your core files with a ‘clean’ version of WordPress. To do this, download the latest version of the core WordPress software from WordPress.org.

Once you have the file, unpack it and delete the wp-content folder in the downloaded files, so you don’t overwrite your plugins, themes, or media files.

To upload the clean files, access your website via FTP and navigate to your site’s root folder. Next, upload all the WordPress files from your computer.

This process might take a while and you will need to say yes when the FTP client asks if you want to overwrite the files on your server. Also, bear in mind that if you’ve made any modifications to core files, such as your site’s .htaccess file, this process will overwrite them.

When the upload is done, go ahead and try to access your website once more. If the error persists, it’s time to bring out the big guns.

4. Use WordPress’ database repair functionality

One thing you may not know about WordPress is that it comes with a database repair function, which can help you fix corrupted tables.

Before you can use this feature, you need to enable it. To do so, access your website via FTP, head to your root folder, and look for the wp-config.php file. Next, open it using a text editor:

WordPress' root folder.

Scroll to the bottom of the file and look for the line reading That's all, stop editing. Now add the following code before this line:

define('WP_ALLOW_REPAIR', true);

Once you save the changes to wp-config.php, you can access WordPress’ database repair feature by visiting the following URL:

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

Replace the yourwebsite.com placeholder with your own domain, and you’ll see the following screen:

Repairing your database to fix the error establishing a database connection in WordPress

When you’re ready, click on the Repair Database button and let WordPress do its thing. When the repair is over, you’ll see a success message, which is your cue to check if the Error establishing a database connection in WordPress message is gone.

If you’re still seeing the error, it’s a sign that your host should get involved. We’d recommend reaching out to them for a fix to the error.

Conclusion

Your database is what makes everything in WordPress possible. Without it, WordPress can’t store or retrieve information, which breaks your site. There are a lot of issues that can cause errors when connecting to your database, but fortunately, they’re usually easy to troubleshoot.

If you run into an error establishing a database connection in WordPress, there are several ways you can fix it, including:

  1. Restoring a recent backup that includes your database
  2. Checking for corrupted WordPress theme and plugin files
  3. Reinstalling WordPress core files
  4. Using WordPress’ database repair functionality

Subscribe To Our Newsletter

Leave a Reply