Submit Free Blogs and Articles

How to Resolve “Error Establishing a Database Connection” Error?

Error Establishing a Database Connection banner-2-min

WordPress is the best and easiest place for the content management system (CMS) which is written in PHP and that uses a MySQL database. At present, this is a unique place for blogging and website building.

But sometimes users face different types of errors on WordPress website that disables your website for users to use. One of them is “Error Establishing a Database Connection”. The first developer doesn’t need to panic about this error. This is a common error in WordPress. But you have to resolve these bugs quickly because they can affect your sales, traffic, and analytics.

Here we will discuss why users encounter this type of error and how they can quickly get away from this issue. Let’s know quickly-

Causes by which users suffer from this problem

When the user is unable to connect to the database properly, the user sees an “Error establishing database connection” error. Many things can affect the connection with a database. Like:-

  1. Due to incorrect login details.
  2. The database may have been corrupted.
  3. Your WordPress files have become corrupt.
  4. Due to high traffic on your website.
  5. Your database server may have been down.

How users can get away from the “Error establishing a database connection” error?

Contact with Your Web Host Provider: To quickly resolve your problem, directly get in touch with the web host provider. This is the best idea to easily resolve your problem. They will inform you where the actual problem is and if there spikes in traffic or not.

If they inform that there is no problem on their side then move on to the second step.

Check Database Connection Credentials: The most common reason for this error is your incorrect data credential. You can experience this type of bug when you recently move your WordPress site on another site to a new host.

The WordPress data credentials details are store in the wp-config.php file. You have to check the below-given details in the wp-config.php file. Here you have to confirm that your database name, username, password, and database hose are correct or not.

/** Name of the database for WordPress */

define( ‘DB_NAME’, ‘provide_database_name_here’ );

/** MySQL database username */

define( ‘DB_USER’, ‘provide_username_here’ );

/** MySQL database password */

define( ‘DB_PASSWORD’, ‘provide_password here’ );

/** MySQL hostname */

define( ‘DB_HOST’, ‘provides_localhost’ );

You can confirm all details from WordPress hosting account dashboard. If anything is updated wrong then you can correct the information in the wp-config.php file.

After conforming to Database Connection Credentials then check your host information is correct or not.

Most of the WordPress hosting companies use localhost but some use separate servers to host databases. In that case, your database host information will not be localhost. For that, you have to contact your WordPress hosting company.

Check Plugin or Theme Files: If WordPress files get corrupted then users can suffer from this issue. There are multiple reasons by which your WP file becomes corrupt, like:- maybe you updated the plugin or theme, and the whole thing collapsed, Maybe you have edited some files manually, and others.

To resolve this, follow below details:-

  1. Connect to your host with FTP.
  2. Now go on wp. content and rename its subfolder plugin folder name, like the plugin to plgin_ or anything other.
  3. Now check the error persist or resolve.

If your problem resolves then correct their file name and go on plugin subfolder and rename all subfolders one by one to know where is the actual problem. Don’t forget to update the right folder and subfolders name.

If the problem not resolves, check the theme folders and subfolders just like you checked plugin details.

Repair WordPress Database: If your WordPress Database is corrupted then you can suffer from this problem. For this users have to repair the WordPress database. For this, you have to add the below-given line in your wp-config.php file.

define(‘WP_ALLOW_REPAIR’, true);

After doing this follow, visit on below given location and repair the WordPress database.


After doing this, remove the repair code from the wp-config.php file.

Check Database Server: After doing all the above this your problem persist then there are possibilities of the Database Server down. To confront this direct contact with the web host provider that the MySQL Server is responsible for this bug or not.

As well as also go on the hosting dashboard then open phpMyAdmin and trying to contact with database.

If you become connect then you have to confirm your database user has sufficient permission. For this you have to create a file name is testconnection.php and paste the below-given code in it:-


$link = mysqli_connect(‘provide_localhost’, ‘provide_username’, ‘provide_password’);

if (!$link) {

die(‘Could not connect: ‘ . mysqli_error());


echo ‘Connected successfully’;



If this script is properly connected, then it means that you have sufficient permission, and there is something else that is wrong. Visit the wp-config.php file and resolve your issue.

Wrapping It Up

I hope this article much helpful for resolving “Error Establishing a Database Connection”. I am much confident that after following the above steps you can easily resolve your problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

Share via
Copy link
Powered by Social Snap