The error “Error establishing a database connection” is very common in WordPress. It literally means there is an issue connecting to database server. This issue may be caused either by wrong info in WordPress code files or Database server is unable to respond to queries sent to them.
Let’s look at all possible reasons one by one.
Wrong database server info in wp-config.php file
Make a backup of wp-config.php file and look for following details and make sure they are correct.
- Database name
- Database username
- Database password
- Database hostname
As shown in below snap.
Database server issue at your WebHost
If you are sure that wp-config.php file has all correct info then contact your web host. May be database server is down or you have reached allotted space or query limit.
You may be Hacked
One of the possible reason of this error is that your WordPress site has been hacked and it is spamming the db server. In this case scan your site & clean it from hack.
Other Possible Reasons:-
- Many Web hosts don’t use database host as default
'localhost'. Look at database details.
- In some cases overwriting your WordPress installation with latest version of WP fix the error.
- Look at spacing of four values database name, user, password, host.
'localhost' & ' localhost' are different.