Type to search

How to Fix WordPress Error Establishing a Database Connection?

An error establishing a database connection on WordPress is pretty common. One faces such a situation while trying to access the WordPress website.

The problem is pretty concerning because when a user faces it, WordPress becomes inaccessible. As a result, the website goes down and loses traffic.

To clear out the entire concept, we have come up with a guide that can provide you with the information for both the causes and solutions for the error. 

Error Establishing a Database Connection WordPress: Explained

So, why does “WordPress \” error establishing a database connection\”” occur? First of all, one should know that WordPress works through two technologies viz, PHP and MySQL. While the former is a programming language that is helpful for writing WordPress software, the latter (MySQL) is used for storing the content items (title, post, pages, widgets) of WordPress.

Both PHP and MySQL are required to make WordPress work. Through a PHP command, WordPress gets connected with the MySQL database.

This then helps to present the information on your screen. It is clear that PHP and MySQL are important to run WordPress successfully.

When WordPress is unable to connect to the MySQL database through PHP commands, this error occurs. It comes with an error message that states “Error establishing a database connection” on WordPress. 

What Causes WordPress “Error Establishing a Database Connection”?

To solve a problem, it is important to know the cause behind it. So, let’s take a quick look into some of the reasons that may result in this error

  • Changed or Incorrect login credentials like username and password
  • A plugin that is not coded perfectly
  • High website traffic
  • Down database server

Problems are quite prevalent with WordPress and require an immediate fix. Seo Agency Dubai has a team of capable individuals that can resolve issues related to WordPress effortlessly. 

5 Easy Methods to Fix Error On Establishing a Database Connection With WordPress on Localhost Xampp

Users claim that they tend to face this error on using a XAMPP server. Although the problem is pretty concerning, there are various ways by which you should be able to resolve it. Here, we are going to mention them one by one for you. Try each of them and check which one works for you. 

Method 1: Repair the Database

To resolve this WordPress error you will have to start with repairing the database. That’s because a faulty database can be the prime reason behind the issue.

A database repair is necessary when you see an error message “One or more database tables are unavailable” message. This appears mostly when one tries to visit the website.

Now, in order to repair the database, you have to first go to the wp-admin.php file. Simply follow the points mentioned below:

  • Add the “1 define( ‘WP_ALLOW_REPAIR’, true )” code in the file. This code will help you to repair the database that is running on WordPress. 
  • After running the above code, next, you have to go to the “www.yoursite.com/wp-admin/maint/repair.php”.
  • On doing so, a page will appear next on the website. On that page, you will get two similar options.
  • First, you will get a “Repair” option which will help you to repair the database. 
  • The second option that you will get is “Repair and Optimise”. This option is for repairing and optimizing the database for protecting WordPress.  
  • You can select either from the repair or the repair and optimize option. Although, the former is better for a quick repair than the latter.

Note: The line of code that you have put in the wp-admin.php is not protected and anyone can get its access. So, you have to remove the line of code from the file before you start the repairing process.

Method 2: Check the Login Credentials in wp-config

As mentioned earlier, the error can occur if you have changed or provided incorrect login credentials. Thus, in order to resolve the error, it is better to change both the Database username and password. Follow the steps mentioned below to do so easily

  • Open the wp-config file and search for the database login information on the file. (You will find the information at the top of the wp-config.php tab.)
  • Search for the database name, it will be “DB-NAME”  and the login user name will be “DB-USER”. The login password will be shown as “DB-PASSWORD” and the database host will be “DB-HOST”. 
  • After checking all the information make sure that all the information is correct. Because WordPress won’t open if there is an incorrect value.
  • If you see that the database name, password, and database host is not the same as mentioned above, you have to change accordingly to fix the error in WordPress.

Method 3: Remove the Corrupted Files

If the errors still persist, then you can try removing the corrupted files of WordPress. This is because most of the users have complained that they have repeatedly faced this issue due to the same.

Thus, we would recommend you to eliminate the corrupted files from WordPress in order to resolve the issue.

Note: Before you start, make sure to back up all the data that is saved in WordPress. You can do it either manually or through a plugin.

On doing so, all the folders that are corrupted will get replaced with new ones. Follow the steps mentioned below to perform this solution

  • Firstly, you need to download a fresh copy of WordPress CMS from WordPress.org.
  • Next, you have to open the file in the drive and remove the wp-content folder and wp-config folders. This ensures that there is no overwriting on the current wp-config file that you downloaded. 
  • When you are done with the removal process of all the corrupted WordPress folders, you have to paste the rest of the folders into the WordPress root folder using the File Manager application.

Method 4: Check the Hosting Provider

WordPress setup error establishing a database connection can also occur if there are issues with your Database server. Hence, if such is the case then maybe it’s time to resolve it for an easy fix.

Check whether there are multiple connections to your database. This is because sometimes there is a certain limit for database connections. When the limit for it increases, the error may occur.

In order to resolve the problem, you can use a caching plugin. This will decrease the database interactions easily. 

Method 5: Check for any Corruption with Plugin or Theme Files

Any plugin or theme update can result in the corruption of WordPress files. If such is the case, then you can easily resolve the issue by following the steps given below

  • First, connect to your host through FTP by providing the login credentials of the FTP account. If you do not have them with you, simply go through the web host emails or consult the chat support representative.
  • Once you connect to the server go to the WordPress root folder. Check for subfolders “wp-content” and “wp-admin”. 
  • Rename the plugin folder with something else. Go back to the website and check if the error resolves. If it does, repeat the same procedure for all the plugin folders.

So, these are some of the solutions following which you should be able to resolveWordPress error establishing a database connection” (Also known as ”apache error establishing a database connection”) easily.