You might have seen above error If you are a blog owner or visited a blog having connection issue.Error establishing a database connection issue is rally frustrating error in wordpress when you are dealing with your own blog.
There are many reasons behind this issue.In this article we are discussing all issues behind error establishing a database connection in WordPress and solution to each of those.
Sometimes it happens without doing anything. Last week we have been facing the same issue and spent almost 30 minutes to fixed connection issue. We didn’t find a complete guide for this problem anywhere so, decided to write a detail fixed for this error “Error establishing a database connection ”
The Main cause of “Error establishing a database connection in WordPress” ?
The actual reason is your WordPress blog couldn’t established a connection with MYSQL Database server. there may be several reasons
- Database table corrupted or not found inside database.
- May your database credential changed
- Currently your database server overloaded and not giving response
Majority of times,if you haven’t changed anything -then reason could be some sort of database server error.
Check If issue occurs for ‘/Wp-Admin’ directory ?
Go to your WordPress admin area by simply go to “yourblog.com/wp-admin”. in that case if you are getting the same error – Error establishing a database connection then you have a other subsequent fix.
If you are getting error like – “One or more database tables are unavailable.” then database may need to be repaired as you may missed some table that your blog or plugin required
Make sure that – before applying any changes take your database backup first.as this required some expert level editing in your WordPress installation.
To repair WordPress database, simply add a single line in your wp-config.php file available in your root directory
[php] define('WP_ALLOW_REPAIR', true); [/php]
After adding above line simply access – www.yoursite.com/wp-admin/maint/repair.php and click on repair database button. If your issue remain unresolved then you need to continue reading article and go for second reason.
Reason : WordPress Database Credential changed
Sometimes you changed your MySQL database password and forget to update those details in your wp-config.php file which is main crucial file in WordPress which holds all database connection information
By Using FTp Software or your WebHosting Cpanel , you can check wp-config to verify your database details matching with current
[php] define('DB_NAME', 'database-name'); define('DB_USER', 'database-username'); define('DB_PASSWORD', 'database-password'); define('DB_HOST', 'localhost'); [/php]
DB Host value will be different based on your web hosting provider like Hostgator, Dreamhost, BlueHost. Majority of users had this issue when they migrate their web hosting or domain name and forget to changed wp-config.php values.
My SQL Database server – WordPress Database Unresponsive for some period of time
Some times if you buy cheap web hosting and your site have heavy traffic that could result in MYSQL server downtime due to number of open connection. if you have well popular site, I suggest please shift to best web hosting provider who provide good server response on a heavy load environment.
There might be the reason sometime web host was under maintenance so, some period database may get down.please contact your web hosting support team.
We tried to give each possible cause for this error, feel free to share your experience in this particular situation so, that can help others to save time to fix database connection error.
Comment below and share this article.
Note: You will get free service from me to fixed Error establishing a database connection in WordPress cheers 🙂