How to deal with WordPress site prompts "Error establishing a database connection" or "Error establishing a database connection" error

When using a browser to access a website built on WordPress, you sometimes encounter the "Error establishing database connection"or"Error establishing a database connection" error message. This article will detail the cause and solution of this problem to help you quickly get your website back up and running.

How to deal with WordPress site prompts "Error establishing a database connection" or "Error establishing a database connection" error

Description of the problem

When you visit a WordPress website in your browser, you may see the following error message:

  • "Error establishing database connection."
How to deal with WordPress site prompts "Error establishing a database connection" or "Error establishing a database connection" error
  • "Error establishing a database connection"
How to deal with WordPress site prompts "Error establishing a database connection" or "Error establishing a database connection" error

This usually means that WordPress is not connecting properly to theMySQL Database, causing the site to fail to load.

Cause of the problem

The problem is usually caused by the accessed WordPress web program not being able to connect to the MySQL database properly. Common causes include:

  • MySQL database service not running
  • Incorrect database login credentials (user name, password or database name)
  • Database server address error
  • Database corruption

prescription

To resolve this issue, you need to check if the MySQL database service is running properly and reconfigure the database connection information in your WordPress website program. Below are the specific steps to do this:

1. Check MySQL database service status

Log in to your MySQL database server and execute the following command to view the status of the MySQL database service:

systemctl status mysql

If the MySQL database service is running in the state active (running), indicating that the database service is running normally, displays the following message:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2023-07-03 15:57:24 CST; 1h 30min ago
   ...

If the MySQL database service is running in the state inactive (dead), indicating that the MySQL database service has been stopped, displays the following message:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Mon 2023-07-03 14:57:34 CST; 1h 30min ago
   ...

In this case, the MySQL database service needs to be started. Execute the following command to start the service:

systemctl start mysql

If you are prompted with an ERROR error during startup, you need to modify the database service configuration according to the error message and then re-execute the startup command.

2. Testing MySQL database connections

After confirming that the MySQL database service is running properly, test whether you can log in to the MySQL database properly. Execute the following command:

mysql -u -h -p

Description:

  • <User>: MySQL database username
  • <IP>: IP address of the MySQL database
  • <Password>: MySQL database password

If you are prompted to log in successfully, but the database password is wrong, you need to change the password of MySQL database again. Please refer to the official MySQL documentation for details.

3. Modify the WordPress configuration file

After confirming that the database password is correct and you can log in properly, change the database connection information in the WordPress website program. Edit wp-config.php file by replacing the file's DB_PASSWORD The database password corresponding to the field is replaced with the correct MySQL database password.

with the CentOS 7 operating system,wp-config.php The file path is /usr/share/nginx/html/wordpress As an example, execute the following command:

vim /usr/share/nginx/html/wordpress/wp-config.php

Find the following:

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

commander-in-chief (military) 'your_database_password' Replace the MySQL database password with the correct one.

To save and exit the file, type :wq and then press Enter Key.

How to deal with WordPress site prompts "Error establishing a database connection" or "Error establishing a database connection" error

summarize

With the above steps, you can effectively solve the WordPress website prompt "Error establishing database connection"or"Error establishing a database connection"Error. Ensuring that the MySQL database service is running properly and that the database connection information is properly configured in the WordPress configuration file is key to getting your website back up and running.


Contact Us
Can't read the article? Contact us for a free answer! Free help for personal, small business sites!
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: info@361sale.com
Working hours: Monday to Friday, 9:30-18:30, holidays off
Posted by photon fluctuations, retweeted with attribution:https://www.361sale.com/en/12442/

Like (0)
Previous July 3, 2024 am11:25
Next July 3, 2024 3:15 pm

Recommended

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

020-2206-9892

QQ咨询:1025174874

E-mail: info@361sale.com

Working hours: Monday to Friday, 9:30-18:30, holidays off

Customer Service
In order to facilitate global user registration and login, we have canceled the telephone login function. If you encounter login problems, please contact our customer service for assistance in binding your email address.