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:
- 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
andwp-admin
. Look for a file calledwp-config.php
and open it up. - 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');
- Log into your cPanel or hosting panel and verify that:
- The database name that has been created for WordPress matches the
DB_NAME
. - The username and password for the user associated with the WordPress table are both correct and have ALL Privileges on the table.
- 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}
- The database name that has been created for WordPress matches the
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.
- 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
andwp-admin
. Look for a file called.htaccess
and open it up. - 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 likeAddHandler 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:
- 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.’
- When you export the database, select SQL as the type of export and save it to your computer.
- Create a new MySQL database with a new name, new user (with ALL Permissions on the database) and new password.
- Log into the new MySQL database and in the gray bar across the top of the panel, select ‘Import.’
- Select the export file you just saved to your computer, and import those tables to the new MySQL database.
- Open up your
wp-config.php
file as described above, and update theDB_NAME
,DB_USER
andDB_PASSWORD
- 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.
Thanks a lot . I totally forgot about recursive function . It helped me in a project.