The listings featured on this site are from companies from which this site receives compensation. This influences where, how and in what order such listings appear on this site. Advertising Disclosure

This error is evident when your website fails to connect to the database. The reason due to which this error occurs is entering or updating incorrect credentials such as database host, database username, and database password. Just because of this error our database does not respond to your requests and its functionality becomes very sluggish. This error can also lead to database corruption and it will be a little difficult for beginners to fix this problem.

Now we will suggest you some troubleshooting tricks to get rid of this problem along with its possible causes. You can follow these steps to fix this issue and stay in a relaxed mode.

Possible causes of a Database connection failure

All the relevant data of a software or application is stored in the database. This data is stored, organised and retrieved whenever required. The wordpress uses that database to store your content for a particular website. Every time we visit the website, the wordpress automatically gets connected to the database. WordPress use the information such as database name, username, password and server. The configuration file ‘wp-config.php’ stores all that information. But if any of these information is incorrect, WordPress will fail to establish a connection with the database and the error ‘Error establishing a database connection ’ would appear.

Other possible causes can be a ‘Server down’ or ‘Corrupted database files’. Now I will give you some of the perfect solutions to this problem, which you can try to troubleshoot the problem this problem.

Relevant and Easy solutions – Troubleshooting tricks

1. Check Your WordPress Database Credentials

Incorrect database credentials can be the most common possible reason behind this error. Make sure that you have entered the correct information in the ‘Wp-config.php’ file.

  1. For that, log in to your hosting account and under the database, section click on ‘MySQL databases’.
  2. After that you will be navigated to the database management system page where the ‘Database Name’, ‘Database Username’, ‘Database users’ along with the links to change the password of the respective users are displayed.
  3. Now you can ensure and check whether all this information is correct or not. If it is incorrect then you can simply edit the correct information in the ‘Wp-config.php’ file.
  4. Now visit the website again and see if the error is fixed or not. If not you can continue with the next troubleshooting step.

2. Check Your Database Host Information

Now if you have gone through the above step and are sure about the correct credential in the database, then there might be an issue related to the incorrect database host information. Generally hosting companies use the local host as the default database host. But some of the companies opt out to use separate servers to host databases. So in that case, you need to enter the correct database host information instead of using the localhost as the default database. For that, you can contact your database hosting company.

3. Repair WordPress Database

Now if you are getting an error message such as “One or more database tables are unavailable. The database may need to be repaired”, then it simply means that your database requires a quick repair. To do that, simply add the following line in the ‘Wp-config.php’ file. Keep that in mind that this line must be added before the “That’s all, stop editing! Happy blogging ” line.

Define(‘WP_ALLOW_REPAIR’, TRUE);

After doing that go to the given page to check the settings:

http://www.yoursite.com/wp-admin/maint/repair.php

Remove this line from the ‘Wp-config.php’ after the repair of the database is done.

4. Check if Your Database Server is Down

After doing all the above steps, if your database connection error still exists then there might be a problem with the server down. This can be possibly due to excessive traffic on the database server. The users would not be able to access the website and an error message is displayed to them.

  1. The best method to confirm a server is down is to contact the hosting company and questioning them about the problem.
  2. You can also check your other websites, if the same problem is encountered on that or not?.
  3. Now if you want to verify that is it a ‘server down’ problem or anything else, you can do it on your own. You need to create a new file ‘testconnection.php’ and then insert the following lines of code in that.
< ?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) { 
die('Could not connect: ' . mysqli_error());
} 
echo 'Connected successfully'; 
mysqli_close($link); 
? >

Just enter your username and password in the respective mentioned places in the code. Simply upload this file to your website and then try to access it through the browser.

Now if this configuration is connected successfully, the user has enough permissions and something else is creating an issue.