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.

图片[1]-如何处理WordPress网站提示“建立数据库连接时出错”或“Error establishing a database connection”错误-光子波动网 | WordPress教程、Elementor教程与故障修复

Description of the problem

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

  • "Error establishing database connection."
图片[2]-如何处理WordPress网站提示“建立数据库连接时出错”或“Error establishing a database connection”错误-光子波动网 | WordPress教程、Elementor教程与故障修复
  • "Error establishing a database connection"
图片[3]-如何处理WordPress网站提示“建立数据库连接时出错”或“Error establishing a database connection”错误-光子波动网 | WordPress教程、Elementor教程与故障修复

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 (username, 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 then 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.

图片[4]-如何处理WordPress网站提示“建立数据库连接时出错”或“Error establishing a database connection”错误-光子波动网 | WordPress教程、Elementor教程与故障修复

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 tutorial? Contact us for a free answer! Free help for personal, small business sites!
客服微信
Customer Service
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: [email protected]
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
This article was written by Harry
THE END
If you like it, support it.
kudos1.4W+ share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments