How to Fix the Error Establishing a Database Connection in WordPress

Roshan Bajaj
How

How to Fix the Error Establishing a Database Connection in WordPress

This is among the common errors that most web users encounter. There are several reasons that can lead into error establishing a database connection WordPress localhost. This can be so frustrating for WordPress beginners especially when it takes place yet you have not made any changes in the settings. This issue can take you close to 20 minutes to fix especially when you have to do some research before fixing it. The challenge is that there is very minimal information on this error online. This article will guide you on how to fix this error. Its wise to make sure that you have enough data backups before making any changes in your database. Here is the guide on how to fix error establishing a database connection displayed in the screen shot below.

Error Establishing a Database Connection in WordPress

  • Why does this error occur?

The main reason behind this error is the fact that WordPress is non-in a position to establish a database connection. There are several reasons that can make WordPress become unable to establish a secure connection. May the database login credentials have been changed or are wrong. In other cases, the database server could be unresponsive or the database is corrupted. From experience, I will tell you that this error mostly occurs because of some form of error with the server even though there can be other factors. The most important thing is to have a clear understanding on how to trouble shoot these issues.

  • Is this Problem also evident in the WordPress Admin panel?

How to Fix the Error Establishing a Database Connection in WordPress

You should start by making sure that this problem occurs in both the back-end (WP-admin) and front-end of the site. You can only be able to proceed to the next level if error establishing a database connection WordPress localhost message is same on both ends. If the error you are getting on the WP-admin panel is different like ‘one or several database tables are not available’ then you may be forced to repair the database. You can repair it by including the line stated below before ‘That is all, halt editing and Joyful blogging’ line in the wp=config.php.

After taking this action, you need to visit http://www.yoursite.com/wp-admin/maint//repair.php to view your settings.

As a user, you should not be logged in to be able to access this functionality while setting this define. The primary intention is repairing a corrupted database and users cannot often not log in when they are having a corrupted data base. After you repair and optimize the database, make sure you remove it from the wp-config.php. Continue reading on for more solutions if this repair does not correct the problem. You will no longer have issues with error establishing a database connection xampp.

  • Check the WordPress-Config file

WP-Config.php could be the most important file in the whole WordPress installation process. You will specify the details that WordPress will use to connect to your database here. In case you modified your database password or root password, you will also be required to modify this file. You have to make sure that everything in the wp-config.php file is similar.

Take note that the DB Host value may not necessarily be local host. It will vary depending on the host but it is local host for popular hosts such as Site5, Bluehost and HostGator. You can find the other host values online.

WordPress Error Establishing a Database Connection

We have people who claim that they fixed this problem by replacing the local host with their IP address. This issue is prevalent when you are running your WordPress on the local server environment.

For instance, when you change the DB Host value on MAMP to the IP may appear to work.

The IP’s for online web hosting services tend to vary. If everything in this folder is correct including the typos, then you can judge that there is something wrong with the server.

  • Check Your Web Host or MySQL Server

You will always encounter the error establishing a database connection in WordPress installation when your site records an extremely high level of traffic. This is because the hose server is unable to handle that high volume of traffic especially when you are sharing the hosting. The site will get so slow to an extend of outputting this error for some users. The best way out is to get to the live chat of phone with the provider of the hosting services and confirm from them whether your MySQL server is still responsive.

However, there are a few steps you can undertake to test whether the MySQL server is working by yourself. Test the other sites that are on the same server to see whether they are going through the same issue. Something may be wrong with the server if they are getting the same error. If this is the only site you are having on this hosting, go to your control panel and try to connect to your database through the phpMyAdmin. If the connection is possible, you need to verify whether the database user has enough permission. Create a new folder that is referred to as testconnection.php and then paste the information below in it.

Be keen to replace your password and username. If your connection is successful, then the user has sufficient permission and something else could be wrong. Go back to the wp-config to confirm whether everything is correct there and re-scan for typos. If you are unable to connect to your database from the phpMyAdmin, then something is wrong with the server. However, the MySQL server will not necessarily be down because you may not have sufficient rights for your user. You may even find all the other sites working well apart from the WPBeginner.

You can call the HostGator and they will be able to reset and restore your user permission in some way. Therefore, contacting the host is a sure way of fixing the error establishing a database connection WordPress localhost. Try all these approaches plus what has worked for others until you get a solution for this error. However, make sure you have enough backup for your data because you are at the risk of losing just in case something goes wrong. With all this information, you now understand how to fix error establishing a database connection.

Visited 53 times, 3 Visits today

Roshan Bajaj information

Roshan Bajaj is a lazy person who loves sleeping but his passion, love, and persistence for his Team, Mentors, WordPress and Digital Marketing, keeps him at work and he finds peace in it. His hobbies include finding the truth and being happy accepting it.

About Roshan Bajaj information

Roshan Bajaj is a lazy person who loves sleeping but his passion, love, and persistence for his Team, Mentors, WordPress and Digital Marketing, keeps him at work and he finds peace in it. His hobbies include finding the truth and being happy accepting it.

Related Posts