How To Remove “Error Establishing A Database Connection” Message?

While running a website, due to one single mistake, you can break your website. When it comes to the database then people don’t really feel like playing with it. Creating a new user in the database can be done by not more. Some people face a problem by getting “error establishing a database connection” message at their WordPress website.

In this tutorial, I am going to tell you how to fix error establishing a database connection message? Many people ask about it and want to know the reason. I will tell you about it.

What Do You Mean By Error Establishing A Database Connection?

Your website is build up with two types of languages PHP and MySQL. You should know how it works? PHP codes are used to store every detail you need. But it can’t show the page until it connects with the database.

All the details are checked in the database before proceeding further. If all the credentials are good then you will see the results. An error will be shown if the connection with the database can be made.

Reasons To Get “Error Establishing A Database Connection” Message:

Basically, there are three reasons for showing this error message.

1 : Your database may be corrupted. If that’s the reason then you can repair it using WordPress only. WordPress can do it for you.

2 : The details you have entered in your “wp-config.php” file are wrong. That means the database name, password, host name may be wrong due to which you are seeing an error message.

3 : The last one is due to your Web hosting website. Sometimes your website may go down due to the slow server.

You Can Remove Database Connection Error:

All the three reasons have their own solutions. You can remove database connection error very easily.

1 : If your database is corrupted then you just have to write a simple code in your “wp-config.php” file and you are done. While opening your wp-admin if you get “one or more database tables are unavailable” then it means your database is corrupted.

To fix it you just have to add:-

define( ‘WP_ALLOW_REPAIR’, true );

After adding this code open this URL :-

www.yourdomain.com/wp-admin/maint/repair.php

Make sure that you replace “yourdomain” with your website’s name. A page will be shown to you asking to repair the database or to repair and optimize the database. Click at “repair and optimize database” and if the database is corrupted then it will be repaired.

Make sure that you remove the code after repairing the database. It is not safe for your website. Hacker can use it.

2 : If your login details are wrong then you have to check them and correct them. You can do it by searching your “wp-config.php” file in your file manager>>web root>>wp-config.php and you can edit this file. Search for login details in this file.

define( ‘DB_NAME’, ‘database_name’ );

define( ‘DB_NAME’, ‘username’ );

define( ‘DB_PASSWORD’, ‘database_password’ );

define( ‘DB_HOST’, ‘localhost’ );

Check all the fields and match them with your original details. If something is not same then correct it. Remember that DB_HOST may not always be “localhost”. But for most of the web hosting websites, it is localhost. You can ask it to your web hosting customer service.

3 : This is the last one to solve. When you use a shared web hosting then it is possible that you may face downtime. There are many websites running on the same host. It may create a problem with your website. Before talking to your web hosting company, you can check other websites running on the same web host.

To remove database connection error, you should talk to your web hosting. Just ask them to check your website. Maybe their MySQL server is down.

Have You Removed the “Error Establishing A Database Connection” Message?

I hope you have removed the errors. As I have explained there may be three reasons for this error message to show. It is very important to remove database connection error because you can’t open your website without fixing it.

Many people ask how to fix error establishing a database message? I hope those people have got their answer. If you still face any problem then I am here to help you.

by Ravi Chahar

A WordPress Professional and the LinkedIn Influencer. A coder by passion and a blogger by choice. WordPress theme development is his forte. He is your WordPress guy who will teach you how to solve WordPress errors, WordPress security issues, design issues and what not.

Get Free Updates Into Your Inbox

Learn Everything Just Like I Did

SUBSCRIBE

6 comments

  1. Hi Ravi,

    Thanks for that helpful explanation.

    It’s happened to me in the past and it was scary. Luckily for me my hosting company were excellent, but for someone who doesn’t get the same level of support that I get, your article will be a superb help.

    Joy

    1. Hi Joy,

      It is always recommended that you should choose your web hosting providers wisely. But, it’s good if you can solve these kinds of problems your own. I mean if you talk to your web hosting providers then it will take the time to recover your website.

      It’s better that you do it your own and within few minutes you can remove all the errors shown at your website. Database connection error can be resolved very easily. At least you can try.

      Thanks for your support.
      Have a lovely day.:)
      ~Ravi

  2. Hi Ravi,

    Thanks for this tips. I already faced this problem at my old domain talkandtalkers.us When it was 4 months. I googled about it found the tips at wpbegginer.

    But my sad story was, i was not able to solve that issue. Then i contact my web hosting provider. They took almost 2 days to respond with a good news. They successfully solved the problem. Now the moral is you can do it by yourself or contact your hosting provider.

    Thanks for visiting my website. Keep visiting us.

    ~Taposh

    1. Hey Taposh,

      Database connection error is the most common error when you transfer your website from one host to another. I have faced it. When it comes to this error then bloggers should try to do it their own.

      As you have said your Web hosting company will always be there for you. But they will take the time to solve your problem. It’s always good that you should learn more about such errors.

      Thanks for sharing your thoughts.
      Have a great day.
      ~Ravi

  3. How I wish I could’ve had this post years ago. I was dealing with a lot of errors like this back then on different sites and it took me days to fully comprehend what to do haha

    Great explanation Ravi! ?

    1. Hi Dennis,

      It’s always a problem with the database. I have faced it a lot with my website. Most of the time this kind of error is displayed just because of the wrong credentials. People forget to change the name and password of the database in wp-config.php file.

      The database error connection is the pain in the ass. It can be solved very easily.
      Thanks for taking the time to share your thoughts.

      Enjoy your day.
      ~Ravi

Leave a Reply

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