How to fix “Error Establishing a Database Connection” in Dreamhost

by Elaine on January 30, 2012

After reading the news on Techcrunch that Dreamhost was hacked and passwords need to be changed immediately, I frantically changed all my passwords.  I literally changed all my passwords on Dreamhost for every user account and database user that I have. After changing all my Wordpress database user passwords, I had a nagging feeling that something would go wrong, and it did.  I visited my Wordpress based Cmsmind.com  and The-Webhosting.com and found this error message waiting for me:

“Database Error: Error establishing a database connection”

Database Error - Error Establishing a Database Connection Database Error – Error Establishing a Database Connection

I was able to fix the problem right away because I knew what the problem was.  The database name and password are stored on 2 different places.  Information in both places must match before permission to connect to the database is granted.

  • When you Install WordPress, the database name and password were automatically generated
  • This database username and password is stored in 2 different places: 1. a static config file in your file server and in the 2.  Dreamhost account.
  • The database username and password is stored in Dreamhost so you can manage the user privileges
  • The database username and password is stored on the config on file server as a connection document since files need to constantly talk to your database.
  • If you change the password in Dreamhost account, but not in the WordPress config file, you will get this error message.

Overview of How to fix:

Well I chose to change the password on the WordPress file server, so these are the high level steps that I took:

  • Edit user name to have SSH access in Dreamhost
  • Find the current database password in Dreamhost
  • SSH into your domain name and edit the WordPress config file in the File Server

1.  Edit FTP User name to have SSH access in Dreamhost

Dreamhost - Allow FTP User SSH Access Dreamhost – Allow FTP User SSH Access

Enable your FTP user to have SSH access so you can telnet into your account/or you can choose to use FTP the file.  In that case you can skip to Step 2.

  • Login to your Dreamhost panel
  • Click on ‘Manage Users’, Click on ‘Edit’ for your username
  • In Manage Users window, Editing User, set the following value:
      •  User Account Type = Shell account – allows SFTP/FTP plus ssh access.
  • Click on ‘Save Changes’

2.  Find the Current Database Password in Dreamhost

Dreamhost- Edit the Database User Dreamhost- Edit the Database User
  • Click on ‘MySQL Databases
  • Under ‘Databases on this server’, select the ;User with Access’
  • Under MySQL Databases at the bottom, you will see ‘Password Currently”.  For example – myNEWpassword
  • You can copy that password to be used in Step 3

3.  SSH into domain and Edit WordPress Config File

  • Telnet or SSH into your domain name with the username and password from Step 1
  • cd into your website directory
  • type:

    Dreamhost - Edit the WordPress wp-config.php file Dreamhost – Edit the WordPress wp-config.php file

pico wp-config.php

  • Search for code that says:

define(‘DB_PASSWORD’, ‘myOLDpassword’);

  • Change the password to the new password from Step 2

define(‘DB_PASSWORD’, ‘myNEWpassword‘);

  • Press ‘Control-X’ and save your file

After you save your file and refresh your website, the error message should disappear.

Hope that helps!

BTW, all the information I listed above are all sample data.  None of these username, password, db_hostname, database names are valid on my website.

Elaine

Elaine

Elaine is the founder of CmsMind, an online blog providing Joomla and WordPress tips. Elaine has been blogging and publishing content for 2 years but has over 10 years experience in creating websites with Joomla and WordPress. When she is not online, she is either Marathon and Ironman training or travelling and racing somewhere in the world. Find her also at: CmsMind, Premium Themes and Templates, and at Webhosting Tips.

More Posts - Website

Leave a Comment

*

Previous post:

Next post: