Troubleshooting WordPress – Error establishing database connection

“Error establishing database connection” is an error message sometimes seen on WordPress sites. What this means is that your WordPress site has lost it’s connection to your WordPress database. This is often caused by a mismatch between the database password WordPress is using and the database itself.

The database settings in your site’s wp-config.php file need to match your database credentials to be able to connect. Here is an example of the database settings from wp-config.php:

/** MySQL database username */
define('DB_USER', 'MyDBusername');

/** MySQL database password */
define('DB_PASSWORD', 'MyDBpassword');

/** MySQL hostname */
define('DB_HOST', 'localhost');

If your site is part of a ReachONE UpTime hosting package, then the “Error establishing database connection” may have been caused by changing your administrator’s password in the UpTime web interface. By default, your database password is tied to your administrator account password. You can change this behavior by going to the “Edit Database” link on the left hand side of the page, click on the “Passwords” tab on the right. Choose “Custom Password”.

Correcting the issue:
Update your database settings in your site’s wp-config.php file to match your database credentials

If your website is not hosted on UpTime, or is not a WordPress site, you may still see this error message if your site cannot connect to your database. Make sure the CMS (Content Management System) or other hosting product you are using has the correct database settings in the appropriate configuration file. If this does not resolve the issue for you, or if you have additional questions, please contact the ReachONE support team.

How do I update my WordPress Database settings?

Much like changing your WordPress Site URL, WordPress database settings can be configured in the wp-config.php file. Simply edit the following lines in the wp-config.php to update your database host, name, username, and password:

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘myDBname’);

/** MySQL database username */
define(‘DB_USER’, ‘myDBuser’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘myDBpassword’);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

How can I change my WordPress Site URL?

WordPress sites can be “broken” by having an incorrect “Site URL” specified in your WordPress settings. Symptoms may include unexpected redirects, or for the site content to only load partially. It may also create problems logging in to the WordPress administration portion of your site to change the Site URL. Fortunately, there is an easy way to override the Site URL, by simply adding a couple of lines to a WordPress configuration file. Add the following two lines to wp-config.php file, making sure to replace the example URL with the URL of your website:

define(‘WP_HOME’,’http://example.com’);
define(‘WP_SITEURL’,’http://example.com’);