Visiting WordPress website prompts" Error establishing database connection"

This article introduces the causes and solutions of the error message "An error occurred while establishing a database connection" when accessing a WordPress website through a browser.

Problem Description


When using a browser to access a website based on the WordPress template, an error message "Error establishing a database connection" or "Error establishing a database connection" is displayed. The specific error examples are as follows.

• Prompt "Error establishing database connection"

• Prompt "Error establishing a database connection"

Problem Causes


This problem is usually caused by the program of the WordPress website being accessed cannot connect to the MySQL database normally.

Solution


When this problem occurs, you need to check whether the MySQL database service is normal on the server and reconfigure the MySQL database password connected in the WordPress website program. The operation steps are as follows:

1. Log in to your MySQL database server.

2. Run the following command to check whether the MySQL database service is normal.

systemctl status mysql

• If the running status of the MySQL database service is active (running), it means that the database service is running normally. The following display example is displayed, then proceed to step 3 to test whether you can log in to the MySQL database normally.

• If the running status of the MySQL database service is inactive (dead), it means that the MySQL database service has stopped, and the output is as follows, then perform the following operations:

Run the following command to start the MySQL database service.

systemctl start mysql

Note If an ERROR error is displayed during startup, you need to modify the database service configuration according to the error message, and then execute the command again to start the MySQL database service.

3. Execute the following command to test whether you can log in to the MySQL database normally.

mysql -u -h -p

illustrate

is the MySQL database user name.

is the IP address of the MySQL database.

is the password of the MySQL database.

The echo information indicates that you can log in to the database but the database password is wrong. At this point, you need to change the password of the MySQL database again.

4. After changing the password of the MySQL database and verifying that you can log in normally, change the password of the MySQL database connected to the WordPress website program.

Execute the following command to edit the wp-config.php file (the configuration file of some versions of the WordPress website is wp-config-sample.php), replace the database password corresponding to the DB_PASSWORD field in the file with the MySQL database password, and modify the location as shown in the figure below Show.

Note This operation takes the CentOS 7 operating system and the wp-config.php file path as /usr/share/nginx/html/wordpress as an example.

vim wp-config.php

5. Type :wq and press Enter.

Save and exit the wp-config.php file.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us