A database connection error can make your WordPress site inaccessible to visitors. Here's how you fix it! 



There are a few possible reasons for the ‘ERROR ESTABLISHING A DATABASE CONNECTION’ message appearing on some websites, including those hosted by Dreamhost which is one of many providers available today as well as self-managed servers where users have full control over their own system settings and possibly more than one WordPress installation sharing an IP address or DNS hostname with other sites making them difficult identity specifically at fault without doing detective work ourselves here though our best guess would be that any plugin installed may interfere somehow.

WordPress error establishing a database connection -  How to fix it



Check Your Database Host Information

If you are confident that your database host information is correct, then make sure to verify it with the hosting company. Most WordPress hosts use localhost as their server name but some managed ones may have separate databases on different servers and this means that there will be an additional step in verifying where these URLs go too - just like any other URL parameter for directory access (i.e., http://myserver/?_loc=name).


It can get tricky when looking through log files because they contain Denise.

Must visit:  Best WordPress hosting India

Check if Your Database Server is Down

If everything seems to be correct, and WordPress still cannot connect to the database, then your database server (MySQL server) may be down.

This could happen due to heavy traffic on a server. Basically, your host server just cannot handle the load (especially when you are on shared hosting).

Your site will get really slow and for some users, it may even output the error. So the best thing you should do is get on the phone or live chat with your hosting provider and ask them if your MySQL server is responsive.

If you have other websites running on the same server, then you can check those sites to confirm that your SQL server is down.

If you do not have any other site on the same hosting account, then simply go to your hosting dashboard and try to access phpMyAdmin and connect the database.

If you can connect, then we need to verify if your database user has sufficient permission. Create a new file called testconnection.php and paste the following code into it:


1
2
3
4
5
6
7
8
<?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>


Make sure to replace the username and password. You can now upload this file to your website and access it via the web browser.
If the script is connected successfully, then it means that your user has sufficient permission, and there is something else that is wrong.
Go back to your wp-config file to make sure that everything there is correct (re-scan for typos).

Post a Comment