How to fix the error by establishing a connection to the WordPress database

website with errors

The photo shows the ‘error in establishing a database connection (error Establishing a database connection) on a WordPress website? This error is one of the most common WordPress errors and makes the website inaccessible to anyone who visits it.

When we see the error we will not be able to visit the site or access the backend of the same, this is because the site is unable to communicate with the database and therefore retrieve all the necessary information.

In this article, we will find out what are the most common causes that generate this error and we will explain the possible solutions in order to correct the error in establishing a connection to the database.

What causes the failure to establish a database connection

There are three main problems that lead to the error in establishing a database connection. One of the major causes of this problem is attributable to an incorrect setting of the database information within the WordPress configuration files.

Secondly, we find the possibility of a damaged database or the impossibility, most of the time temporary, to reach the server where the database is located.

But what does the database content that is so important? In short, all the information on your WordPress site. In fact, the database contains post data, page data, meta information, plugin settings, login information, etc.

So data on your hosting such as multimedia contents (images, videos, etc.), theme system files, plugins are useless without a database that associates your settings and custom texts.

Database Connection Errors

When a user reaches the website some files retrieve all the information from the database showing the visitor the page as we have set it. So if this communication does not happen we receive the error: error in establishing a connection to the database.

Check your WordPress database information

WordPress to connect to the database needs identification information such as: your name, username, password, and host (server). All this information can be retrieved from our provider and is stored in the wp-config.php file.

If any of this data is incorrect, WordPress will fail to reach the database displaying the error “Error establishing the connection to database”.

To check this information, you will have to connect via FTP or through your provider’s panel to the files on the server, then you will have to open the wp-config.php file

At this point, you will have to check the various information entered carefully and check that they are correct. If you need help you can ask your provider that the information you have is correct.

Verify that the database is up and running

If the data in wp-config.php is correct and you continue to get the error: Error establishing a database connection, we need to check that the database server is accessible and operational.

The downtime of the server could depend on various factors, one of these is the high traffic generated by visitors. In this case, the site will become very slow and may return the error randomly.

A test you can do is to connect to your provider’s dashboard and try to access phpMyAdmin. If you are able to connect and browse without problems the problem is not attributable to the server, otherwise, you should contact your provider for more information.

Repair the WordPress database

If trying to access the WordPress site you get an error other than “Error establishing a connection to the database” it may be necessary to repair the database.

In fact, it may happen that an incorrect update procedure or malicious code damages the database, compromising its correct functioning.

To repair the database you will need to add the suggested line below just before the message “ That’s it, stop editing! Happy Blogging. ”(That’s all, stop editing! Happy publishing.) Inside the wp-config.php.

define('WP_ALLOW_REPAIR', true);

Next you will need to reach the page to repair the database. To reach this page it will not be necessary to access the website, but just reach the correct address:

Since this page will be accessible to anyone who visits it, once the repair is complete, go back to wp-config.php and delete the previously added line.


We have seen some of the common causes that generate the error: Error establishing a connection to the database. We have also seen some solutions for the aforementioned error.

Have you ever encountered this error? If you need further help, we recommend that you contact us via the form on our WordPress support page.

Related Posts

No Results Found

The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.

Call Now Whatsapp Consultation!