You have already faced the problem of the error establishing a database connection on others sites or on your own site. It can be frustrated if you are a newbie in WordPress. In this article, I will show you how to fix error establishing a database error in WordPress in detail.
First thing first, why are you getting this error?
You are getting this problem because you site is not able to connect to the database properly because of some unknow issues. Maybe, you are facing the problem, you didn’t put the correct login credentials (username, password, database name) or it have been changed by someone. Maybe your database has been corrupted because of some bad plugin or server.
Are you facing the problem for /wp-admin as well?
First, you should check you are getting this problem on front-end or back-end or both sides. If you are getting this error on the /wp-admin/ side, you may have to repair your database if message is something like “Database tables are not available and the database need to be repaired”. If the error is popping up on both sides so maybe you didn’t put the database login credentials correctly.
Repair the database if you are getting repair error
Go to your root directory and open config.php and add the following code
[code type=”codetype”]define(‘WP_ALLOW_REPAIR, true);[/code]
When you have done that, you can go directly via the URL http://www.yoursite.com/wp-admin/maint/repair.php. You will find the screen like this:
Click on the “Repair Database” to repair the database. Please don’t forget to backup your database first.
Fixing the wp-config.php file
Check your database login credentials. It could be like this:
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
/** MySQL hostname */
Check your MySql server side
You may have facing the problem because of lot of traffic coming to your site and your server is unable to handle too much load (you may have facing the problem if you are on shared hosting but you can face this problem on dedicated hosting too as I have faced). So, quickly contact to your hosting provider’s representative and ask them that your MySql server is responsive or not.