If upon browsing your WordPress blog or website you find a mostly blank page with an error message that says something like “Error Establishing Database Connection” it generally means that your MySQL database credentials changed, or your .htaccess file is corrupt.

Start out by verifying your MySQL credentials:

  1. Connect to your server via FTP and browse to the root of your site. This is where you’ll find folders like wp-content, wp-includes and wp-admin. Look for a file called wp-config.php and open it up.
  2. Look for the following lines:
    /** The name of the database for WordPress */
    define('DB_NAME', 'your_db_name');
    
    /** MySQL database username */
    define('DB_USER', 'your_db_username');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'your_db_password');
    
    /** MySQL hostname */
    define('DB_HOST', 'your_hostname');
    
  3. Log into your cPanel or hosting panel and verify that:
    1. The database name that has been created for WordPress matches the DB_NAME.
    2. The username and password for the user associated with the WordPress table are both correct and have ALL Privileges on the table.
    3. Check the hostname that your hosting provider requires for WordPress. It defaults to localhost but this can be different depending on the host. For example, MediaTemple uses $_ENV{DATABASE_SERVER}

After you’ve completed those steps, try accessing your site again. If it still isn’t working:

Check for a corrupt .htaccess file

If you recently moved hosting providers or even just moved server to server, there is the possibility that a setting in your .htaccess file is breaking the rest of your WordPress installation.

  1. Connect to your server via FTP and browse to the root of your site. This is where you’ll find folders like wp-content, wp-includes and wp-admin. Look for a file called .htaccess and open it up.
  2. Look for anything above or below the #START WORDPRESS / #END WORDPRESS block of rules that looks out of the ordinary. I know that’s vague but it depends on the hosting set up. Keep in mind that some plugins like Yoast’s SEO and W3 Total Cache add rules to the .htaccess file and those rules should be left alone. If you see something like AddHandler php5-script .php try removing it, saving it to the server and reloading the site.

If neither of the above methods worked, it’s possible that your MySQL database has been corrupted in one way or another, or the name is invalid and you didn’t get any specific errors for that. In that case you may be better off doing an export of your MySQL database, and then dumping that database and creating a new fresh one.

To start with a fresh WordPress database:

  1. Log into your MySQL database using something like phpMyAdmin,  and select your WordPress database. Be sure to select the whole database, not just a single table inside. In the gray bar across the top of the panel select ‘Export.’
  2. When you export the database, select SQL as the type of export and save it to your computer.
  3. Create a new MySQL database with a new name, new user (with ALL Permissions on the database) and new password.
  4. Log into the new MySQL database and in the gray bar across the top of the panel, select ‘Import.’
  5. Select the export file you just saved to your computer, and import those tables to the new MySQL database.
  6. Open up your wp-config.php file as described above, and update the DB_NAME, DB_USER and DB_PASSWORD
  7. Upload the updated wp-config.php file to your server and log in to your (hopefully) fully functional WordPress site!

The above fixes should work in most cases, but if you’re stuck, confused or just don’t want to worry about breaking anything, I’m happy to help! Get in touch and we’ll get your site working ASAP.