How to Fix WordPress Database Connection Error

RECOMMENDED: Click here to fix Windows errors and optimize system performance

The “error establishing a database connection” is probably one of the most common and scary errors that WordPress users may encounter. It is certainly a close link with the White Screen of Death (WSOD). This error means that your website no longer communicates or accesses your WordPress database and your entire website is down. This is not an easy task and you should try to solve it immediately as it can have a direct impact on your sales, traffic and analysis.

But don’t worry, today we’ll discuss some common scenarios that cause this error and some simple ways to get your website up and running in no time.

Why do you get this error?

In short, you get this error because WordPress cannot connect to a database. The reason why WordPress cannot connect to a database can now vary. It is possible that your database connection information is incorrect or has been modified. Your database server may not respond. Your database may have been corrupted. In our experience, this error is usually due to a server error, but other factors can also occur. Let’s see how to solve this problem.

One of the following scenarios can cause this error:

  • Your login information (username and password) may have changed. Even if you hadn’t made the change yourself, it could have happened somehow.
  • If you install a poorly encoded plugin, your database may be corrupted.
  • Your website may experience a significant increase in traffic that exceeds the capacity of your server.
  • Your WordPress hosting may be defective and the database may not work due to a problem at the end.

Contact your Web Hosting Provider

May 2020 Update:

We now recommend using this tool for your error. Additionally, this tool fixes common computer errors, protects you against file loss, malware, hardware failures and optimizes your PC for maximum performance. You can fix your PC problems quickly and prevent others from happening with this software:

  • Step 1 : Download PC Repair & Optimizer Tool (Windows 10, 8, 7, XP, Vista – Microsoft Gold Certified).
  • Step 2 : Click “Start Scan” to find Windows registry issues that could be causing PC problems.
  • Step 3 : Click “Repair All” to fix all issues.


It is safe to assume that if your website only worked a minute ago (or a day) and it is not now, the error may be on your web host’s page.

All high quality hosting providers now offer a kind of reactive support, most of the time via live chat.

Start by contacting this live chat, say you have a “database connection error” (insert sentence), and ask :

  • if the database server is running smoothly, and
  • if there is currently no increase in activity or traffic on the server.

In most cases, if you tell them what kind of mistake you have, they will let you know exactly what the cause is, or they will even correct it for you.

More importantly, they will let you know if your database is OK and if there is any suspicious activity on the server or not.

Checking the WP configuration file

WP-Config.php is probably the most important file in your WordPress installation. Here you enter the details for WordPress to connect your database. If you have changed your root password or database user password, you will also need to change this file. The first thing you should always check is if everything in your wp-config.php file is the same.

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');

Remember that your DB_Host value is not always localhost. This varies depending on the host. For popular hosts such as HostGator, BlueHost, SiteGround, it’s localhost. Other host values can be found here.

Some people suggested solving their problem by replacing localhost with IP. It is common to see this type of problem when running WordPress on a local server environment. For example, with MAMP, the DB_Host value can work when switching to IP.

define('DB_HOST', '');

IP addresses vary for online web hosting services.

If everything in this file is correct (make sure you check for typos), it is fair to say that something is wrong with the server.

RECOMMENDED: Click here to troubleshoot Windows errors and optimize system performance