Remove the Error Establishing a Database Connection in WordPress

Ugh!!

Unable to connect with your database?

Don’t be frustrated!! Even yesterday I also got trapped with this issue. While doing the research I tried out multiple methods to resolve WordPress establishing database error and finally solved. I realize to share this with you. In this article, you will get to know how to fix the error establishing a database connection in WordPress.

First of all, let us talk about what is this WordPress database connection error and what are the very possible common causes?.

Within WordPress, we use MySQL database to store all the information regarding the website and uses PHP to retrieve all the information. “Error establishing a database connection” means that php was not able to connect with your MySQL database to get all the information it was requiring.

Common Causes of WordPress Error Establishing a Database Connection

  • Login Credentials

It’s very common that may be your login credentials are wrong. The database uses login credentials as username and password. If in case you have changed those then it’s obvious that you won’t be able to access the website with wrong ones. So, be careful about this common mistake.

  • Corrupted Database

If by chance you upload some bad plugin, may be that become the cause of corrupted database which causing the connectivity problem.

  • Server Down

May be your server is down due to some error of your web hosting company or you would be experiencing a big traffic that your server is unable to handle.

These are just some causes related to error establishing a database connection in WordPress

Troubleshoot the WordPress Error Establishing a Database Connection

  • Determining the Actual Error

Do you get the error when you are accessing wp-admin? Or you get this different error “One or more database tables are unavailable, It may needs to be repaired”. These may be the signs of the corruption of your database.

As the human body has its own characteristics to repair all the tissues, same as the WordPress has the feature to repair your database, you just only need to enable that.

So, what you need to do is to access your wp-config.php file which has all the WordPress installations settings and their configurations.

Open wp-config which is in your root WordPress file directory. Add this line of code to the bottom.

define (‘WP_ALLOW_REPAIR’, true);

- How to fix the WordPress error establishing a database connection

You can see in the above screenshot, there are two options repair and repair and optimize. You can choose anyone but be careful that optimizing can take a bit longer.

Once you have added that line to your code, be sure to remove it.

  • Checking Database Login Settings in wp-config

The another option you have is checking database settings in wp-config file.

Ever wondered why credentials stopped working even if you haven’t changed them, the reason can be switching hosting companies and changing the user information can make this error as the wp-config was not updated to the new information.

Look into your wp-config.php file again, you’ll see something like this:

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define( ‘DB_NAME’, ‘database_name_here’ );

/** MySQL database username */
define( ‘DB_USER’, ‘username_here’ );

/** MySQL database password */
define( ‘DB_PASSWORD’, ‘password_here’ );

/** MySQL hostname */
define( ‘DB_HOST’, ‘localhost’ );

WordPress can access your database with these four pieces of information.

  1. The name of the database (“DB_NAME”)
  2. The login username (“DB_USER”)
  3. The login password (“DB_PASSWORD”)
  4. The database host (“DB_HOST”)

If any of these value is incorrect, there will be error in WordPress database connectivity.

  • Above Steps Not Working

If above troubleshooting steps are not working for you then there is only one reason left, you should go and check the host’s end. You can contact to the support of the web hosting company and they will remove the error establishing a database connection in WordPress

So, these were some of the points I wanted to discuss with you all for troubleshooting WordPress database connectivity problem.

0

Comments 1

  1. Hello Naveen Sharma,
    This is an awesome information for WordPress users. Database repair is so easy I never heard.
    Thanks.

    Reply

Write a Comment