Image Image Image Image Image
Scroll to top



Fix the Error Establishing a Database Connection in Wordpress

BlogHelpDesk was down for a few days due to an unexpected incident. If you visited this blog earlier this week, you will see the message saying “Error Establishing a Database Connection”.

I tried accessing the WordPress Dashboard Wp-admin but it was also unsuccessful, I saw the same error:


The suggestions in the message didn’t help because I didn’t change the username, password at all, and this is the only site on the hosting that had the issue.

Actually this was not the first time I saw the error, but it lasted just a few minutes previously due to hosting problems. It was a serious issue this time and my site was totally down.

I checked the wp-config.php file but it looked alright. I added a php file with the content below and run it to test the connection to database:

$link = mysql_connect(‘localhost’, ‘username’, ‘password’);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
echo ‘Connected successfully’;

It said that I couldn’t connect to the database, so now I know that the database is the real issue.

I contacted HostGator support immediately and they sucked. This guy couldn’t figure out the problem and he failed to help recover the database.

Unfortunately I had to do it myself and I saw that the database is totally blank. I created a new site using Quick Install in Cpanel and somehow it overwrites my existing database at BlogHelpDesk. That’s so horrible as I didn’t make a backup for this site and it means I lost the whole posts written in the last 3 months.

Therefore, you should be extremely careful when using tools provided in the Cpanel, back up everything before making changes on your hosting. That’s my biggest lesson after the incident.


  1. Arghhhh! This just happened to me! Same thing. I used Quick Install to setup a new WP site and it automatically overwrote an existing DB.

    WTF!?!?!?! I’m beyond livid.

    • Tuan Do

      I hope you had the backup. I had to use Google Cache to recover my site.

  2. Diego

    This just happened to me…fml – and fuck hostgator.

  3. Prafull

    I had this issue today.
    Server had crashed last night and was attended to fairly quickly when the issue was known.
    All worked for a while but today WordPress couldn’t make a connection to the database.
    The Simple Machines Forum database was working ok and the forum would load.
    What I did was:
    1. Create a new database user
    2. Assigned that user to the WP database with full privileges.
    3. Updated WP_config to use that user

    After that all was good.

    Seems that after a server issue the WordPress user privileges can become corrupt or changed even though the user is shown with full privileges.

    Thanks for this post. It pointed me in the right direction.

    • Tim

      My multisite was attacked and I could not get past the login screen because of the dreaded “Error Establishing a Database Connection” message. Prafull’s suggestion helped me get back into the dashboard. THANK YOU!

Submit a Comment