Error establishing a database connection is a most common issue in WordPress. This error can occur because of database login credentials are wrong or have been changed and It could be that your database has been corrupted or database server is unresponsive
How to fix it?
- Check wp-config.php – First, you need to check the information holds in wp-config.php files like database name, username, password, and server. If the given details is similar with created database and user then proceed to next step
- Access wp-admin – When you go with websitename/wp-admin, you can see a different kind of error message stating that your database needs to be repaired. You need to add below lines on the wp-config.php
Note: To start the process you need to access the http://www.websitename.com/wp-admin/maint/repair.php. Once done be sure to remove the added line.
The above process is not worked, There might be a problem with MySQL server. Kindly contact your hosting provider to fix this issue.