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

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

In this article we'll go through the most common 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 one or more incorrect settings in the file containing the database configuration settings.

error-establishing-database-connection

To resolve this error, check the following settings in your configuration file and correct as needed. The location of the configuration file depends on the program. You can find a list of the more common programs and their configuration files in the link below.

Locating program configuration files

Once you know where the particular file is located, you can edit your configuration file with the cPanel File Manager:

Hostname localhost
Database Name Full database name. This has two parts, the prefix will be your cPanel username and the part after the underscore will be the database name.
Example: If your cPanel username is userna5 and the database name is db1, then you would enter userna5_db1
Database UserName Full database username. This has two parts, the prefix will be your cPanel username and the part after the underscore will be the database username.
Example: If your cPanel username is userna5 and the database user us dbuser then you would enter userna5_dbuser
Password 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 most often caused by using the cPanel settings (cPanel username and password) in the configuration settings instead of the specific database username and password. In the following example, the cPanel username is whhsup5, whereas the full database username is whhsup5_mydbuser.

If the database settings are set to use the cPanel usename and password instead of the full database user and its password, the following error will appear if and when you ever change your cPanel password:

database-access-denied-for-user

Checking the file that contains the configuration settings, you may see something similar to the following:

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

You will want to change the settings to use the full database usrname and password instead. Fortunately, this is easy and quick to fix. Edit your configuration file and edit the DB_USERNAME variable to use the database username and the DB_PASSWORD variable to use password for that database user.

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?

We value your feedback!

Why was this article not helpful? (Check all that apply)
The article is too difficult or too technical to follow.
There is a step or detail missing from the instructions.
The information is incorrect or out-of-date.
It does not resolve the question/problem I have.
How did you find this article?
Please tell us how we can improve our Help Center:
Email Address
Optional, but our team may contact you for more information.
Did you find this article helpful?

Post a Comment

Name:
Email Address:
Comment:
Are you a bot?
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

News / Announcements

Update to SSL Certificates - Certificate Warnings
1969-12-31 11:00 am EST
Hits: 624
What is the Heartbleed bug?
1969-12-31 11:00 am EST
Hits: 234

Related Questions

Here are a few questions related to this article that our customers have asked:
Would you like to ask a question about this page? If so, click the button below!

Help 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.