Skip to main content
All CollectionsWebsiteWebsite 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

Updated over a year ago

The error establishing a database connection (“Error establishing a database connection”, “Access denied for user”, or similar) 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 use WordPress, you may refer to a dedicated tutorial here: Error Establishing A Database Connection on WordPress 💡

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


Step 1 — Check the Current Database Parameters

In the Websites section, click on Manage next to the site in question, and search for Databases Management:

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.

If you're not sure about the password of your database, you can change it by following this guide: How to Change the Database Password.

Step 2 — Open the Configuration File

In the Websites section, click on Manage next to the site in question, and search for File Manager:

Choose to access the files of the particular website, open the public_html folder, and look for the website's configuration file there.

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

The result should look similar to 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 configuration.php file inside the public_html folder of your domain. Here, 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

The result should look similar to this:

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

PrestaShop

Open the parameters.php file inside the public_html/app/config folder of your domain. Here, 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

The result should look similar to this:

Moodle

Open the config.php file inside the public_html folder of your domain. Here, 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

The result should look similar to this:

After the new values ​​are set, save the changes and open your website using an incognito browsing mode.

NOTES

  • Some CMS have an additional variable for table prefixes. To ensure the website's configuration 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.; we recommend you leave the default value used in your CMS

If the Error Persists

If the error persists 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?