How to Fix “Error Establishing A Database Connection” in WordPress

Who has ever wanted to create a website and heard that WordPress is one of the most used and easy to manage options?
Surely, this is one of the first possibilities that you have considered to launch your web project.

The installation is easy to execute if you decide to host your website on a hosting in Spain as Webempresa.

However, if you have worked with WordPress before, it is possible that in order to get your WordPress website up and running, you may have performed some of the tasks you will see below:

Sound familiar?

It is common that in this type of executions you will encounter some errors. Let’s see one of the most common ones that we will talk about in this section so that you can learn, without too much effort, to solve the error by connecting the WordPress database.

Database connection error in WordPress

Let’s take a look at the following image to see how this database connection error is displayed on our screens:
error al establecer conexión con la base de datos
Let’s remember an important fact that we must know: for your WordPress website to work properly, it must have properly assigned both files and the database that is associated with these files.

One question we should ask ourselves about this database connection error is whether the information you use to connect is correct. This tends to be the most common problem in most cases and gives rise to this conflict.

Let’s see with an easy three-step process how we can solve this database connection error in WordPress.

Locate the wp-config.php file

From the WePanel of your hosting account, locate the File Manager Application. You can see this first guideline in the following image:

Administrador de Archivos Cpanel
When you login, locate your website files and within these files, locate the wp-config.php file. This is the one that has the connection data to the database.
Ubicar el archivo wp-config.php

Verify connection data

When editing this file, locate the following data:

define('DB_NAME', 'cuenta_nombreBD'); define('DB_USER', 'cuenta_nombreUser'); define('DB_PASSWORD', 'claveUserBD'); define('DB_HOST', 'localhost'); 
As you will see, these are the DB_HOST connection data. And in most servers localhost is always used, therefore, the data that you have to check are the three that we indicate below:

– the database name DB_name_account,
– the user assigned to the database account_nameUser,
– the password of the user keyUserBD.

MySQL Database connection data

From the WePanel of your hosting account, locate the Database section and then MySQL Database.

Opción de Base de datos MySQL en WePanel
Here you must verify the name of your database and if the assigned user is the correct one.

In addition, you have the option to view the user’s privileges by clicking on the user name link, make sure he/she has all the privileges.

Pantalla base de datos actuales
In this same screen at the bottom you have the option to change the user’s password. Proceed to modify it since it is possible that it is not the correct one.
Cambio de clave usuario base de datos
With these database name, database user and password changed, you only have to update your wp-config.php file if necessary.

¿Do you still have a database connection error?



By executing this simple process, the database connection error should be resolved, however, if you are still having problems, then you can check what I suggest below:

If you have problems with your database server.

This case is rare, you can rule it out by installing a new WordPress website through the automatic installer or if you have more than one website on your account, and they all have the problem, then it could be a server problem.

In these circumstances, we recommend you consult with the hosting support where you host your WordPress.

If your database is corrupted.

In this other case you would have to re-export your database and import it again.

Another option that I propose you is that from your WePanel of your hosting account, enter in the section “Database > MySQL Database”, and try to correct the database, as you can see in the following image:

Opciones de verificación y reparación de base de datos

Conclusions



As you have seen, fixing the database connection error in WordPress is not that complicated.

If you want to avoid a headache, using the guidelines we have discussed will allow you to see your website published and in perfect condition for your users to browse it.

Hosting Vitamins

Icono Velocidad Servidores Alta Velocidad
High speed servers
Icono Velocidad Servidores Alta Velocidad
Free Image Optimization
Icono Velocidad Servidores Alta Velocidad
Magic Caché
Icono Velocidad Servidores Alta Velocidad
Uptime 99.9% guaranteed
Icono Velocidad Servidores Alta Velocidad
Free SSL Certificate

Hosting Tutorials

Icono Velocidad Servidores Alta Velocidad
What is a hosting
Icono Velocidad Servidores Alta Velocidad
What is a domain
Icono Velocidad Servidores Alta Velocidad
What are DNS
Icono Velocidad Servidores Alta Velocidad
What is NGINX?
Icono Velocidad Servidores Alta Velocidad
What is a web server
Icono Velocidad Servidores Alta Velocidad
What is Apache
Icono Velocidad Servidores Alta Velocidad
What is GitHub
Icono Velocidad Servidores Alta Velocidad
Shared hosting
Icono Velocidad Servidores Alta Velocidad
Shared or Dedicated Hosting
Icono Velocidad Servidores Alta Velocidad
Difference between web server and hosting
Icono Velocidad Servidores Alta Velocidad
What is a VPS
Icono Velocidad Servidores Alta Velocidad
WordPress ddbb connection error
Icono Velocidad Servidores Alta Velocidad
What is web cache