Error Establishing A Database Connection

Error Establishing a Database Connection

The most challenging error in WordPress is “error establishing a database connection” that can be considered as one of the top listed errors in WordPress. If we elaborate this error in easy wording, then we can say that due to this error your website is not communicating properly with the database and the link of your website goes down.

As this error affects your traffic and analytics on the website so it is very important to overcome this issue as soon as possible.

If you are unable to overcome this issue then your sales charts goes down and creates problems for you to maintain your website at a good level. In this article we will discuss some easy and most valuable scenarios to get rid of this error. 

Error Establishing a Database Connection

As the information of post data, page data etc on your WordPress is saved into MySQL database. However, the data of media content like images and theme core files are not stored into MySQL database. The PHP helps to display the information in the browser that is required to the visitor by executing the code.

Don’t Miss : Teamviewer Alternatives – 10 Best Remote Desktop Softwares

If the PHP does not work properly due to some reason it leads to issue called “error establishing a database connection “. Due to occurrence of this error the whole page becomes a blank page with white display and no data on page, as shown below

This error not only breaks the fronted of your website but also stops you to access the website.

When this problem is happening and the visitors want to access your website the 500 HTTP status code and internal server error appears. This status shows that something is wrong in server and the requested page by the visitor is delivered. In case proper website working, it will generate 200 HTTP code that shows that everything is fine.

Why exactly does this error happen?

There are few reasons due to this error occurs and this error can be resolved within 20 to 30 minutes easily. The main reasons are given as

  • The use of wrong login credentials
  • Database server’s issue
  • Occurrence of corrupt file in WordPress installation, often done by hackers.
  • Due to a lot of plugs-in, themes and deleting files by user leads to the problem in which database is corrupted.

Read Also : Truecaller Online – Search Unknown Mobile Number Without Using The App

Fix the Error Establishing a Database Connection

You should always backup before the initialization of the troubleshooting on the server or to fix things on your website. The most famous WordPress backup plug-in is duplicator and updraft plus that saves all files in its storage.

Once you have backup, you can start troubleshooting or fixing your database issue. After fixing the problem you can restore a backup. Once you have backup, then the following actions should be performed.

#1 Check Your Database Login Credentials

First thing that should always be noted is the database login credentials. You have check whether they are correct or incorrect because this is the common reason due to which the problem “error establishing a database connection” occurs.

The WordPress website’s connection credentials are located in wp-config.php file and this file located at WordPress website root. It has following four important information slots that should be correct in all way.

Now the question comes to our mind is how to access wp-config.php. So, we can access it by connecting our website using SFTP and then browse the root of website or in case of cPanel click on file manager and browse the root of your website and then click to edit file. cPanel file manager looks like following figure.

Wp-config.php credentials are given in the following figure that shows “what the file looks like when opened”.

Now you have to check your credential as shown in the above figure and update your wp-config.php file. Please note that you should update user and password value. This will resolve your problem.

If you have followed all steps mentioned above and still seeing the error establishing a database connection message, then proceed to the next step called troubleshooting step.

#2 Repairing Corrupt Database

Sometimes due to constantly addition or removal of hundreds of tables by new plug-in or themes corrupt your database. This problem happens in some cases not very often. If you receive the following error when you login in your WordPress website’s dashboard, it’s mean that your database has been corrupted.

Actually, the WordPress has repair tool that can be initialized. You should add following text into your wp-config.php file.

After doing above mentioned step, browse the WordPress website given below

After browsing this website you will get the options of repair the database or repair or optimization of database. You should go with the option “repair the database” as it is faster.

After running the repair process you have to delete the code that you have entered above in your wp-config.php file. In case of cPanel, you can run the repair process within MySQL database, as shown in following figure.

Or you can also repair from phpMyAdmin. For this process you have to just login phpMyAdmin and go into database and choose the tables. From the dropdown menu, you have to choose the repair option, as shown below.

If you are still facing the problem on your website, then proceed to the next troubleshooting step.

#3 Fixing Corrupt Files

The error establishing a database connection message is also appeared if some or your entire files have become corrupted. Corrupted files problem may be due to an issue when you transfer files using FTP or due to hackers which try to gain access on your website. To solve this problem, you have to download a fresh copy of WordPress from the company website WordPress.org. After downloading this file, unzip it in your PC or laptop and delete following two folders from the file.

Wp-content

Wp-config-sample.php file

After that upload the remaining files via SFTP on your website and overwrite your already existed file. This will remove all problem creating files and replace them with uncorrupted files. Also clear your browser cache after doing this task. After performing this process check website whether this error has been resolved or not. If not then restore the backup.

#4 Restore Latest Backup

The last but not the least method to remove this error is to restore your database backup if required. Sometimes this is the faster way to resolve this issue if you have done backup previously and are worried about losing the data. Note that you have to restore both database and all your files.

I hope this article helped you to get your website back in good running condition.

There is one great article about How to Fix the Error Establishing a Database Connection Problem in WordPress at 000webhost. Click here to view – 000webhost.

Categories:

No Responses

Leave a Reply

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