The error establishing a database connection ("Error establishing a database connection", "Access denied for user .." or similar errors can be easily fixed and pinpointed to a few things worth checking first:

  1. Check the current database parameters

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

If you are using WordPress, here's a full tutorial for you: Error Establishing A Database Connection in WordPress.

For other CMSs, let’s take a look at the steps closer:

Step 1 - Checking the current database parameters

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

You will need these credentials:

In order to save these, you can copy them to a TXT file or leave the databases tab open on your browser.

Step 2 - Open the configuration file

Now it is time to open your configuration file. You will be able to find it by opening Websites → Manage, and searching for File Manager:

Step 3 - Matching the credentials

In the configuration file, find the fields responsible for your website connecting to the database and specify the correct data. In the case of the most popular CMS, one of which you may have installed:

OpenCart

In the directory, /public_html/config.php needed fields will be DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, and DB_DATABASE. You need to specify the correct values ​​in this way:

DB_HOSTNAME - MySQL Server;

DB_USERNAME - MySQL User;

DB_PASSWORD - The password that you specified when creating the database;

DB_DATABASE - MySQL Database;

Once filled up, it will look like this:

Another configuration file can be found in /public_html/admin/config.php directory, needed fields will be the same as in /public_html/config.php.

Joomla

In the directory, /public_html/configuration.php find the fields public $ host, public $ user, public $ password, and public $ db. You need to specify the correct values ​​in this way:

public $ host - MySQL Server;

public $ user - MySQL User;

public $ password - The password that you specified when creating the database;

public $ db - MySQL Database;

Once filled up, it will look like this:

NOTE:

  • You do not need to add additional spaces or erase existing symbols (such as “)” and similar) - this will lead to an error.

After the new values ​​are set, save the changes, and reload the site page using Ctrl + F5 buttons.

If the error persists

If the error persists after you’ve gone through all the steps it usually means that the password you’ve set to your database is different from the one set in the configuration file.

No worries, you can easily fix it by opening up your configuration file and copying the current password:

NOTE:

  • Make sure to copy the password only (without any symbols like “)“ or similar)

That’s it! Now you know how to fix Error establishing a database connection error 😊

Additional resources:

Did this answer your question?