Your WordPress page built with the PHP code has all of the posts and data input saved in a secured database known as the ?My SQL database?. The role of this database is to provide the necessary information, which a visitor seeks from your page, with the PHP code.
But there are circumstances when the database feels hard to deliver the information; might be due to the wrong input of credentials or a server error, etc. In this situation, your website will display a message ?error establishing database connection?.
Most of the times, the error gets resolved on its own when the server works back normal whereas in other cases, you will have to fix it on your own by knowing the cause of the error.?Here Is The List Of The Common Causes And The Steps To Fix This Common WordPress Error.
1. Check For The Credentials Mismatch And Fix It
If you have changed your login credentials recently or if in case you have changed your hosting service provider, then the error might have occurred due to the wrong entry of credentials.
This can be fixed quickly. Open the wp-config.php file from the file manager of your cPanel. Here you will find all the credentials of your database; cross check the credentials to see if anything is wrongly input. Modifying the input values in the?case of mismatch will solve this issue.
2. Repair The Corrupted Database
If you get the same error message when you login as wp-admin, then your database is OK. But, if you get a different error message such as ?One or more database tables are unavailable?, then it indicates that your database is corrupted. This can be solved by enabling the database repair option.
To Do This;
- Go to the wp-config.php file and enter the code, define (?WP_ALLOW_REPAIR?, true);
- Following this, you should open your browser and type, http://yoursite.com/wp-admin/maint/repair.php
This will redirect you the page asking you to choose between ?repair database? or ?repair and optimize database?. Choose any one among the two, preferably the second option to solve all issues. Once finished, delete the code added before and click save to secure your website.
3. Delete Corrupted WordPress Files
The next method of solving the issue is to delete the corrupted files from your database. For this, you will have to backup the copy of your files and download a new WordPress file from the WordPress.org and unzip the contents to the computer.
Following this, navigate to the extracts folder and delete the old folders (wp-config.php and wp-contents) to remove the corruption. Now, proceed uploading the new files using the file manager and reload the page.
4. Fix The Server Overload Problem
If none of the solutions above solves your problem, then it could be probably because of the server overload or malfunctioning. If you are on a shared server, then the site traffic must have created the overload and is the cause for the error message displayed.
This can be solved by contacting your host service provider and check for the responsiveness of MySQL server.
Thus, the error displayed could be due to many reasons as stated above. Any one of the methods explained will definitely solve your problem and establish your database connection. If the problem still persists, you should contact your service provider and get help from them.