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. Find the website’s configuration file.
  3. Match parameters of your actual database with the configuration file.

Let’s take a look at these steps closer:

Step 1 - Checking the current database parameters

Go to the list of MySQL Databases:

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 configuration file

Now it is time to open your configuration file. You will be able to find it by opening Hosting → Manage → 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:

WordPress

In the directory, /public_html/wp-config.php needed fields will be DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. You need to

specify the correct values ​​in this way:

DB_NAME - MySQL Database;

DB_USER - MySQL User;

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

DB_HOST - MySQL Server.

Once filled up, it will look like this:

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)

And then change the password.

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

NOTE:

Did this answer your question?