All Collections
Website
Website Troubleshooting
How to Fix "Error Establishing a Database Connection"
How to Fix "Error Establishing a Database Connection"

Fixing a database configuration error on Joomla, OpenCart, and other CMS

Ixanar U. avatar
Written by Ixanar U.
Updated over a week ago

The error establishing a database connection ("Error establishing a database connection", "Access denied for user", or similar errors), can be pinpointed to a few things:

  1. Check the current database parameters

  2. Match the parameters of your actual database with the configuration file

If you are using WordPress, you can check a dedicated tutorial here: Error Establishing A Database Connection in WordPress.

For other CMSs, take a look at this video Tutorial or follow the steps below:


Step 1 - Check the Current Database Parameters

Open Websites → Manage, search for Databases Management on the sidebar and click on it:

Next, select the domain from the dropdown list:

Check the List of Current MySQL Databases And Users. You will find there your database credentials:

Copy them to a TXT file or leave the databases tab open on your browser, as you will need these details in the next step.

In case you're not sure about the password, you can change it by following this guide: How to Change the Database Password.

Step 2 - Open the Configuration File

Open your website's configuration file. You will be able to reach it via the File Manager. Go to Websites → Manage, and search for File Manager:

Step 3 - Match the Credentials

In the configuration file, find the fields that connect your website to the database and enter the correct data. Expand the corresponding section for the instructions related to your CMS:

OpenCart

Open the file config.php inside the public_html folder of your domain. You need to specify the values corresponding to your database ​​as follows:

  • DB_USERNAME - The database username

  • DB_PASSWORD - The database password

  • DB_DATABASE - The database name

Once filled up, it will look like this:

OpenCart has another config.php configuration file that can be found in the /public_html/admin/ directory. Open it and enter the same information as in /public_html/config.php.

Joomla

Open the file named configuration.php inside the public_html folder of your domain. You need to specify the values corresponding to your database ​​as follows:

  • public $ user - The database username

  • public $ password - The database password

  • public $ db - The database name

Once filled up, it will look like this:

Make sure not to add any additional spaces or delete any existing symbols to avoid website errors.

PrestaShop

Open the file named parameters.php inside the public_html/app/config folder of your domain. You need to specify the values corresponding to your database ​​as follows:

  • 'database_name' => The database name

  • 'database_user' => The database username

  • 'database_password' => The database password

Once filled up, it will look like this:

Moodle

Open the file named config.php inside the public_html folder of your domain. You need to specify the values corresponding to your database ​​as follows:

  • $CFG->dbname = The database name

  • $CFG->dbuser = The database username

  • $CFG->dbpass = The database password

Once filled up, it will look like this:

After the new values ​​are set, save the changes, and open your website from an incognito window or using Ctrl+F5.

NOTES

  • Some CMS have an additional variable for table prefixes. To ensure the config file value matches the actual prefix, open the database via phpMyAdmin and check the names of the tables. The prefix is a short series of letters followed by an underscore, for example, xhfv_

  • While the default hostname for MySQL is localhost, some CMS use mysql or 127.0.0.1. The recommendation is to leave the CMS default value

If the Error Persists

If the error still appears after double-checking your database credentials and clearing the cache, it usually means that the password you’ve set to your database is different from the one entered in the configuration file.

To fix it, open your configuration file and copy the current password, making sure not to copy any adjacent symbols. Next, set the database password to the one you have copied from the config file by pasting it as the new value.

That’s it! Your website should be working without database errors now 😊

Did this answer your question?