WordPress Error: How to Fix Error Establishing a Database Connection

Running across an error can be annoying at best.

WordPress, like all software, is not foolproof. The most intuitive programs can often have the weirdest of problems.

Having a WordPress error is not the end of the world. Today we are going to over the specifics of fixing the “Error Establishing a Database Connection”.

Let’s get down to it!

Tracking Down the Source

Running a blog of a WordPress website requires a surprising amount of work.

Encountering an error on your database connection seems like an easy enough problem to understand.

The first problem to figure out is where this database connection error may be coming from. Does the same connection problem occur on the backend of your website like it does on the front end?

There are a variety of possible causes for this sort of connection error. Corruption on your WordPress database can happen. You may have mixed up your login credentials at some point.

No matter where the problem starts and whatever the potential causes may be, though, the best way to fix any sort of software dilemma is by troubleshooting some fixes.

Troubleshooting the WordPress Error

To re-establish your database connection, there are a few things to run down.

First, to interact with the editing files in WordPress, you need an FTP Client. With this, you can download and alter the files for WordPress to fix this error.

1. Repairing the Database

Now that you have the FTP Client, use it to attempt to repair your corrupted database. Use your FTP Client to download the wp-config.php file. At the bottom of the file is a line that says, ‘That’s all, stop editing! Happy blogging’.

In the space below that line, copy/paste this code in: define(‘WP_ALLOW_REPAIR’, true);

Reupload the altered file and check to see if the repair works. If the repair does work, remove the code line.

2. Checking the Details

Does the database error problem persist? The next step is to double all the other information in the wp-config.php file.

Double check all the information. Is the database’s username and password correct? The local host information may be off.

If the local host seems to be the issue, try to replace it with the IP address for the database server. This can be a common problem for websites hosted on local servers.

If all the information is correct, then time to move on and troubleshoot problems over the server side.

3. Server Repair

There are many reasons your host server itself may have gotten overloaded. It could be too much traffic at once.

No matter what the problem is, you can contact your server provider. They should have a customer service line to help run you through the troubleshooting process and get a solution nice and quick.

If you prefer to try it yourself, here are some tips to run down as you troubleshoot.

Test other websites on the server. If they also come across the same error, you will need to sort out your MySQL server.

First, access your phpMyAdmin through your cPanel and connect the MySQL database. If it works, verify and test with a new file called testconnection.php. Paste the following code into the file:

$link = mysqli_connect(‘localhost’, ‘username’,
if (!$link) {
die(‘Could not connect: ‘ . mysqli_error());
echo ‘Connected successfully’;

Make sure to put in your own username and password.

After all of this, you may be looking at not enough permission to run given to your website. Tracking down where the permission may be lacking will be a trial and error process.

Keep the Support Line Open

A WordPress error doesn’t have to be the end of the world. WordPress is designed to be simple and easy to use.

The key to solving any software problem is going through bit by bit until you can find a solution for the root cause.

Need more guidance? We here at Blogging.org have plenty of services to help guide you through all steps in your blog making process. Try us out today!