If database settings have not been configured properly for software, errors can occur. Two common errors are:

  • Unable to establish database connection
  • Access denied for user...

In this article we'll go through the reasons for each of these errors and how to resolve them.

Unable to establish database connection

If you see this error instead of your website, it indicates an incorrect setting in the  configuration file.

error-establishing-database-connection

To resolve this error, check the following settings in your configuration file and correct as needed. You can edit your configuration file with the cPanel File Manager:

Hostname: localhost
database name: Make sure this is the full database name which will include your cPanel user name as a prefix (e.g. userna5_mydatabase)
database username: Make sure you are using the database user assigned to the database, and not just the cPanel username (e.g. userna5_databaseuser).
password: Make sure this is the password for the database user assigned to the database.

If needed, you can change the password for your database user.

Once you have corrected the database settings as needed, refresh your website in your browser to make sure the error has been resolved.

Access Denied for User

This error is caused by the cPanel username being used in the configuration file instead of a database username.

database-access-denied-for-user

You may see something similar to the following in your configuration file:

define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'userna5');
define('DB_PASSWORD', '[previous cpanel password]');
define('DB_DATABASE', 'whhsup5_mydatabase');
define('DB_PREFIX', '');

Using the cPanel username instead of a database user in a configuration file will cause this error any time the cPanel password is changed. Fortunately, this is easy and quick to fix. Edit your configuration file and replace the cPanel user name and password with the database username and password for your database.

If you did not create a database user when you created your database, you will want to create a new database user and assign it to your database.

Once you have edited your configuration file, the database settings should look similar to:

define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'whhsup5_mydbuser');
define('DB_PASSWORD', '[new database user password]');
define('DB_DATABASE', 'whhsup5_mydatabase');
define('DB_PREFIX', '');

Refresh your website in your browser and your error should be resolved.

If you have any trouble resolving either one of these errors, please feel free to contact our Support Department for assistance.

Did you find this article helpful?
LLFiggs 2012-08-25 3:00 am
Took the steps mentioned to get rid of "Error establishing a database connection" several times before reading this page, but it doesn't work.

I need another troubleshooting solution.
LLFiggs 2012-08-25 3:00 am
Took the steps mentioned to get rid of "Error establishing a database connection" several times before reading this page, but it doesn't work.

I need another troubleshooting solution.
LLFiggs 2012-08-25 3:00 am
Took the steps mentioned to get rid of "Error establishing a database connection" several times before reading this page, but it doesn't work.

I need another troubleshooting solution.

Login to comment.

Your Opinion Matters

... but we need to know what you're thinking!

I'm Christi Nickerson, your friendly Community Support technician, and I wrote the article you're looking at now. I like to think it's perfect, but I'm sure you have some suggestions. Please, let me know what they are!

Feedback
Your Email Address
Because we'd like to talk with you!

Support Center Search

Current Customers

Email: support@WebHostingHub.com Ticket: Submit a Support Ticket
Call: 877-595-4HUB (4482)
757-416-6627 (Intl.)
Chat: Click To Chat Now

Ask the Community

Get help with your questions from our community of like-minded hosting users and Web Hosting Hub Staff.

Not a Customer?

Get web hosting from a company that is here to help.