Article overview

Help article

Fixing 'Error Establishing a Database Connection' in WordPress

It's possible the error message 'Error Establishing a Database Connection' is shown when visiting your WordPress website.

Although this error message may seem severe, it is actually fairly easy to solve. Essentially, it means your website is unable to connect to the database assigned to it.

This article tells you more about the cause of 'Error Establishing a Database Connection' and, most importantly, how to solve this error message.


Edit your database password

As we've mentioned, you are seeing this error because your WordPress website is unable to establish a database connection.

Your WordPress website contains a configuration file (wp-config.php) in which the login credentials of your database are stored. Your WordPress website uses these credentials to connect to the website's database.

If the database login credentials within wp-config.php do not match the actual credentials of your database, you will see 'Error establishing a database connection' when visiting your WordPress website. This happens when you've changed the database password in your control panel without changing the database password in your wp-config.php file.

To solve this, you can simply use the database password within wp-config.php as the actual password of your database.


Step 1

Log in to the control panel and click 'Shared Hosting' in the menu. Next, select your domain below 'Products'.

Now click 'File Manager' in the top right.

Click on File Manager

See the article 'Using SFTP filemanagement in your control panel' for a guide on using SFTP filemanagement.



Step 2

Open the 'www' folder and click the wp-config.php file with the right mouse button. Click 'Edit' to view the contents of the wp-config.php file.

Open the wp-config.php file



Step 3

You can find the database password inside the wp-config.php file. Scroll down to the line shown below:

/** MySQL database password */
define('DB_PASSWORD', 'ExamplePassword123');

This is the line that tells your website what the password of your database should be (in our example the password is ExamplePassword123). Write down the password from your wp-config.php file and follow the steps below.



Step 4

Now you've written down the password used by your wp-config.php file, it's time to set this password as your actual database password.

Also see 'Creating and managing a database' for more information on using databases.

 

In your control panel, click the 'Site' tab and then 'Databases'.

Click on database



Step 5

Click on the three dots next to the database name, followed by 'Manage users'.

Click on your database name



Step 6

On this page you can change your database password by clicking the databse user that is also listed in the wp-config.php file next to 'DB_USER'. Now enter the password you wrote down earlier and click 'Save'. The database connection should now be re-established and your website should be visible once more.

enter the database password from wp-config.php


Check the other credentials in the wp-config.php file

If you're still getting the 'Error Establishing a Database Connection' message after following the steps in 'Edit your database password', the other database credentials in wp-config.php may be the cause.

To check this, head over to 'Shared Hosting' in your control panel and select your domain name again. Click on 'Site' tab and click on 'Databases'. The image below shows an example of what your database overview looks like.

your database overview

Keep this page open and go back to 'Shared Hosting' in your control panel and select your domain. In the overview, click 'File Manager' in the top right.

Open the 'www' folder, select the wp-config.php file and click 'Edit'. The wp-config.php file will now be opened in your browser.

Search your wp-config.php file for the following lines and check if the database login credentials are correct.

  • Does DB_NAME show the same database name as your database overview?
  • Does DB_USER show the same username as the user you changed the password for?
  • Does DB_HOST show the same hostname you find when clicking the database name in the database overview?

If the information in your wp-config.php file does not match the above, you will need to edit the wp-config.php file (DB_HOSTDB_USER DB_NAME).

Simply change the values between parentheses and press 'Save' at the bottom of the file in the File Manager. Your website will now be able to connect to your database again.

Do not open the wp-config.php file in advanced text editors, such as Microsoft Word. These editors add hidden markup, which renders the wp-config.php file unusable. 



In this article we explained how to fix the 'Error establishing a database connection' message.

If your website is still showing the message after following the steps in this article or if you have any other questions regarding this article, don't hesitate to contact our support team.

You can reach them using the 'Contact us' button below or via the 'Contact' button inside your control panel.

If you wish to discuss this article with other users, feel free to leave a comment below.

Has this article been helpful?

Create an account or log in to leave a rating.

Comments

Create an account or log in to be able to leave a comment.