Open the contents index












This guide was updated on

You try to visit your site and all you see is a white screen with the writing “Error establishing a connection to the database“?

3 steps to resolve the connection error to the WordPress database

Before you start … do you have a backup of your site? Does your hosting provider offer automatic backups? Are you able to generate one now, even if your site is unreachable? Before making changes to the database and / or files, I recommend that you download a copy of the most recent backup available for your site.

1) Contact your hosting provider

The first thing to do for resolve the connection error to the WordPress database is to contact your hosting provider. Especially if you use a shared server space and / or if you have no practice in working directly on WordPress databases and files.

If you haven’t made any changes to WordPress, the files or the database, and your site suddenly doesn’t work, there may be a server overload problem.

In this case, some users may be able to see the site. Others probably see a screenshot. Still others perhaps see the error connecting to the database.

If you use a shared service, server overhead may not necessarily be due to a spike in traffic on your site. Rather, to a traffic spike on another of the sites that share the server with you.

Contacting your hosting provider is therefore the first thing to do to check if the connection error is caused by factors that do not depend on your error or your site, and proceed in the best way to solve the error of connection to the database of WordPress.

In most cases, the operator of the technical support team will also be able to provide you additional information on the type of error found and how to resolve it.

2) Check the wp-config.php file

The file wp-config.php it is one of the most important of your entire site and will be used to solve the error of connection to the WordPress database.

A WordPress site is made up of files (i.e., .php, .css files, etc.) and from a database. If one of these two elements is missing or cannot be reached, a WordPress site cannot exist.

The file wp-config.php serves to create the link between files and databases.

Inside there are various information, including – in fact – database name and credentials to access it.

This information is found below the line / comment:

** Impostazioni MySQL - È possibile ottenere queste informazioni dal proprio fornitore di hosting **

There are three lines:

  • DB_NAME, where the name of the database.
  • DB_USER, where the name of the user associated with the database.
  • DB_PASSWORD where is indicated the password you created for the user.

On a real installation, the file looks like this (in the image below the credentials are partially obscured for security reasons).

wp-config after changes

Even if only one of this information is incorrect, users will see an error connecting to the database.

Then open the file wp-config.php and verify that the credentials are the right ones.

You can open the file directly from the File Manager inside the cPanel (before editing it, I still recommend you download it so as to have a backup copy) or via FTP (in this case, you can download it, edit it with a text editor and upload it again).

The credentials relating to the database are located within the cPanel, in MySQL Databases. Here you will find the names of the databases created on your account with associated users.

If the information relating to the database and associated user is correct but your site still does not work, go to the next step to resolve the connection error to the WordPress database.

3) Follow the procedure to repair and optimize the database of your site

Perhaps, your site’s database is corrupt and to solve the connection error to the WordPress database you will have to follow the standard repair procedure.

First, navigate within the File Manager and find the file wp-config.php.

Download the file to get a backup copy. Then, open it in edit mode.

Now, right after the header

/* Finito, interrompere le modifiche! Buon blogging. */

add the line:

define('WP_ALLOW_REPAIR', true);

Below you see a screenshot of the file with the addition of this code:

wpconfig add allow repair to repair the WordPress database connection error

This line of code is for activate the repair functionality, even when you do not have access to the site and therefore you have to work on it from the outside.

When you’ve added the code and saved the file, visit this url (obviously, replacing with the domain of your site):

Here you will see some instructions with two options:

  • Database repair and optimization, to identify and solve any problems, and optimize the database. This option may be the best but it takes longer. In order for your site to work again, there is no need to optimize the database.

repair database for not having the error of connection to the WordPress database

Selecting the first option, at the end of the repair you will see this screen:

repair result

As you can see, in the end it is suggested to remove the codes you previously added to the file wp-config.php. To start the database repair procedure it is not necessary to insert a credential. This means anyone could do it! Remove the codes define (‘WP_ALLOW_REPAIR’, true); it is therefore essential to disable the functionality and keep your site safe.

If after doing all these things the site still doesn’t work, consider the possibility of restore the last saved backup.

In any case, I still recommend working with your hosting provider to understand what caused the database connection error. If it was not an error on your part, or the update or installation of a plugin, it could be a problem with an automatic update or with the server configuration.

Best WordPress resources


In this guide we have seen how to solve the error of connection to the WordPress database.

If you see this error, try to stay calm. In most cases, it can be resolved without affecting your site or its contents.

Then follow the instructions above to locate the problem; you should be able to make your site visible again in no time.

As usual, now I pass the word to you:

Have you ever seen a database connection error on your site?

How did you solve it?

Have you turned to the support service of your hosting provider or have you adopted one of the solutions described above?

I invite you to let me know by leaving a comment below the post.



Leave a reply

Please enter your comment!
Please enter your name here