Fix “Error establishing a database connection” with WordPress

I’ve run across a few WordPress sites recently that have been spontaneously throwing “Error Establishing A Database Connection.”  Some of the fixes are pretty simple but in a few cases the root cause was a bit more obtuse. Below are a few things to look into that might help fix the issue if it’s happening to your website.

The Easy Ones: Check your wp-config.php file and make sure that all of the following are correct (keep in mind that case sensitivity matters)

  • database host
  • datbase name
  • database username
  • database password

Login to phpMyAdmin and:

  • make sure you can login to phpMyAdmin, if not the database server might be down, contact your hosting provider
  • repair your tables
  • optimize your tables

The less obvious cause of the problem may also be that your account was originally set up to use PHP4 and your hosting provider may have upgraded to PHP5. I’ve seen this twice recently and in both cases the hosting provider had to be conatacted to update the account but it both cases it also fixed the issue. The host in question was DreamHost though I know others will allow you to select the version of PHP you want to use when you set it up.

There is more on WordPress moving to PHP5 though WordPress.org still has the minimum requirements set at PHP 4.3. If the easy fixes don’t bring your site back, look into the PHP version, either way it’s probably a good idea to upgrade if you are still on an older version of PHP.

You may also want to look at the WordPress Support Forums for other options that might be mentioned as well, if you find another solution to the issue not mentioned here please feel free to come back and leave a comment with what you did to fix it so we can help others in the same situation.

About Scott Ellis

Join me on Google+

Scott Ellis: Founder of vsellis.com, co-founder of DZX Medical and CEO & Managing Partner for pixelterra, web producer for geekbeat.tv,mobile strategy consultant and all around techie. Avid hiker, wine lover, guitar player, scuba diver, traveler, photographer and sports fan. You can find Scott anywhere online by looking for “vsellis” or become friends on twitter @vsellis.