One of the most common and worst error is the error establishing database connection in wordpress. This error occurs when your site is longer in connection with your wordpress database and as a result white screen of death appears. Due to this error your site goes down so do not take this error lightly and properly fix the error as soon as possible.
Here we will discuss the factors that causes these errors and how we can resolve the issues and get back your website.
Before analyzing database issues and their solution the first step is to understand what database is and why it is used. So database is a software that helps and make it easy to store, retrieve and to organize data in other software. WordPress uses this database to store and arrange all your data. When any visitor visit your site it then connect with your database.
While connecting with the database wordpress needs these information like
- Database name
- Database username
- Database password
- Database server
All this database information is stored in you’re the config.php file so you can easily see this information. Because if any database information is wrong wordpress will not be able to connect with the database and hence this “establishing database connection error” occurs.
Causes of this error
Error establishing database connection usually causes due to the certain reasons. It can be caused due to providing incorrect database information, due to corrupt database or due to irresponsive database server. These can be the possible reasons due to which your website lost connection with the database. Here is an image of how this error massage shows on your site
Now let’s have a look at how to fix the error establishing database connection in wordpress step by step.
How to fix this error
Before starting analyzing your website we always recommend to take backup because troubleshooting errors may cause more problems or make things worse. So before fixing any issue take backup of your website. After taking backup follow these steps to fix the error.
1-Check database credentials
Incorrect database information is the most common reason of this error and it happens when you recently switch your site to a new host and add wrong database credentials. So first of all check this information which is stored in confide.php file. You can easily access this file and check out the information is correct or not.
|// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define( ‘DB_NAME’, ‘database_name_here’ );
/** MySQL database username */
define( ‘DB_USER’, ‘username_here’ );
/** MySQL database password */
define( ‘DB_PASSWORD’, ‘password_here’ );
/** MySQL hostname */
define( ‘DB_HOST’, ‘localhost’ );
If the database information entered is correct then the error may be due to the corrupt database or due to irresponsive server. But if the entered data is wrong then this can be the reason of the error. You can fix this error from your cpanel as well just follow these images to edit your entered data.
Open your cpanel and search MySQL Database. Click to open the file.
After confirming your database name user name and password you can change the user name and the password of database to avoid establishing database connection error. After this procedure visit your site that is the error has gone and site is working properly or not. If site is showing same error then you have to see more steps to remove this error.
2- Check database host information
If your database information like database name, user name and password is correct. Make sure that you are using the correct host information. Because sometimes user enter correct user information but enter wrong host information. This incorrect information also causes this error. For this purpose contact your hosting company and confirms your database host information.
3- Repairing corrupt database
In few cases your database become corrupt and need reparation. If you receive this type of massage that
“One or more database tables are unavailable. The database may need to be repaired.”
To repair this corrupt database you can add this line to your wp config.php file. You must add this line before stop editing line otherwise wrong placement can cause more error.
After editing wp-config.php file you can check the setting by visiting this page http://www.sitename.com/wp-admin/maint/repair.php
4- Check database server
If the above mentioned methods do not affect the site and the site is still showing the error then your site server must be down. This happens when your site traffic increase and your shared hosting cannot bear this much traffic then the server is down. The site will be slow and for a few users, this error may appear.
The best way to deal with this type of database error cause you should contact your server and ask about your MySQL server that is it responsive or not. You can also ask your host provider for help and to solve this issue. Asking for help is the best way because you do not need to get worry and may cause a more serious error while troubleshooting database connection errors. You can also hire a WordPress developer who is experienced and is able to analyze and to solve the problem.
There are different reasons that causes database connection error. Among these the most common reason is the invalid or incorrect user information. Following these steps you can simply avoid this error but asking for help from your host or any developer will be the best solution because it is safe method. And also do not forget to take backup before applying these methods.