Handling of database connection errors in WordPress

A few days ago, there was a problem with my wordpress URL, and the page showed:

Find it online: https://www.wpbeginner.com/wp-tutorials/how-to-fix-the-error-establishing-a-database-connection-in-wordpress/

Database setup problem

WordPress needs the following information to connect to the database

  • Database name
  • Database username
  • Database password
  • Database server

These information are stored in the file wp_config.php,

Find the following section:

define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'leon' );

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

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Make sure you can log in to access the database according to this information. The main situation is that there is a problem with this part.

Most of the databases are on the local host, that is, localhost, some are not like this, check the connection problem of your database host.

Repair the database

I checked my database connection and there was no problem, so I fell into this part.

Add the following line in the wp-config.php file

define('WP_ALLOW_REPAIR', true);

然后在浏览器里输入:

http://www.yoursite.com/wp-admin/maint/repair.php

Visit the database repair page

Click on reply database

I found that my wp_option data table crashed. After the repair, the website is running normally.

After the repair is completed, remember to remove or delete the repair line in wp-config.php, because you don't need it, and there may be a back door.

Host problem

Especially for shared virtual hosts, the host or database may be running too slowly. Contacting the service provider and restarting is also a method.

 

I will record my experience here. If you are similar, I will help you.

 

Guess you like

Origin blog.csdn.net/leon_zeng0/article/details/113856254