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.
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:
||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
||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
||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:
Checking the file that contains the configuration settings, you may see something similar to the following:
define('DB_PASSWORD', '[previous cpanel password]');
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_PASSWORD', '[new database user password]');
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.