Solution to the Error establishing a database connection prompt in wordpress

Source: Internet
Author: User
Tags autoload mysql client mysql host phpinfo wordpress database

Wordpress prompt

"Error establishing a database connection" indicates that an Error occurs during data connection.

Find the following:

The code is as follows: Copy code
/** Replace "putyourdbnamehere" with the WordPress database name "*/
Define ('Db _ name', 'wordpress ');
/** Replace "usernamehere" with the MySQL database username "*/
Define ('Db _ user', 'root ');
/** Replace "yourpasswordhere" with the MySQL database password "*/
Define ('Db _ password', 'root ');
/** MySQL host name */
Define ('Db _ host', 'localhost ');
DB_NAME is the name of the WordPress database.
DB_USER is the MySQL database user name
DB_PASSWORD is the MySQL database password
DB_HOST is the MySQL host name. Generally, you do not need to modify localhost by default. In special cases, you can change it to localhost: 3306/wordpress.

However, we still cannot solve the problem, so we have the following solution process. The reason for this problem may be:

1. Unable to connect to the database used by Wordpress.

The database username and password in your wp-config.php is incorrect, or the server where your database is located has crashed! It may also be restricted by service providers for a short period of time (a blog with a sudden surge in access traffic or using some WP plug-ins that consume database connections ).

The solution is to confirm that the user name and password information in the wp-config.php is correct. Make sure that the database server used by WP is not suspended (can be pinged or restarted directly ?!). Check whether the database connection mode is a remote connection or a local connection. Some configured remote connections may fail to connect to the database. The Error establishing a database connection prompt will pop up, generally, virtual space (the remote database connection used by the GD space) or shared space are all local connections (localhost ).

2. If the server database is just upgraded to mysql 5.0 or above, the WP blog can be accessed normally before.

This may be because mysql 5.0 adopts a new password verification mechanism, which requires that the client version be later than 4.0 (MYSQL client in PHP can view phpinfo ), the old password mechanism is used to connect to the database. This will prompt an error such as "Client does not support authentication protocol requested by server, the Error "Error establishing a database connection (possibly wrong password)" is displayed in wordpress )".

Solution:

Method 1. Create a new control account for the wordpress database in mysql, and then modify the database username and password configuration information in the wp-config.php. Convenient and simple !!

Method 2: In mysql:

The code is as follows: Copy code

Mysql> SET PASSWORD
-> 'Clin003 & prime; @ 'clin003. Com' = OLD_PASSWORD ('newpwd ');
Mysql> flush privileges;

Here, replace clin003 with the username of the wordpress database, and replace clin003.com with localhost or a domain name. newpwd is the password of the user.

Another point is to view phpinfo (), find the mysql. sock path displayed by MYSQL_SOCKET, and confirm that mysql. sock is in this path. Otherwise, a symbolic link is required. For example, the MYSQL_SOCKET path in phpinfo is/var/lib/mysql. sock, but it is actually located in/tmp/mysql. sock. You can enter the following in the command line:

The code is as follows: Copy code

Ln-s/tmp/mysql. sock/var/lib/mysql. sock

3. Due to improper mysql service settings, the number of mysql connections has exceeded the limit value, or the application design is faulty. As a result, a large number of dormant connections cannot be released in time.

Solution:

Log on to the mysql server

The code is as follows: Copy code

Mysql-u root-p

Use commands

Show processlist;

View the number of current connections. If there are too many processes or a large number of timed-out sleep connections, Edit

The code is as follows: Copy code

/Etc/mysql/my. cnf

Vim/etc/mysql/my. cnf

Add or remove comments in the [mysqld] Field

Max_connections = 500 # increase the number of mysql connections

Wait_timeout = 10 # disconnect a connection that exceeds 10 seconds

4. wp_options database table error. I fixed and optimized the whole database table once.

In wp_options, view the table prefix wp based on your actual situation!

When an error occurs in WORDPRESS, DEBUG the following parameters:
Troubleshooting based on Wp-config.php debugging

1. There is a debug parameter in the wp-config.php, open this parameter, modify:

Define ('WP _ debug', 'true ');

2. Solve the problem according to the error prompt, such as the following error:

WordPress database error: [Table './clin003_com/wp_options' is marked as crashed and shoshould be retried Red]
SELECT autoload FROM wp_options WHERE option_name = '_ transient_doing_cron'

WordPress database error: [Table './clin003_com/wp_options' is marked as crashed and shoshould be retried Red]
SELECT autoload FROM wp_options WHERE option_name = '_ transient_timeout_doing_cron'

WordPress database error: [Table './clin003_com/wp_options' is marked as crashed and shoshould be retried Red]
SELECT option_value FROM wp_options WHERE option_name = '_ transient_doing_cron' LIMIT 1

The wp_options table is broken and needs to be repaired. Use the mysql client.
Run the fix command in mysql to fix the problem:

The code is as follows: Copy code
Mysql> repair table wp_options;

You can also use phpMyAdmin to fix the issue.

3. Solve the problem and turn off DEBUG.

Troubleshooting based on mysql log records

Log files in mysql

The code is as follows: Copy code

Mysql/data/

Find a file ending with. err and open it. See a row

'. \ Clin003_com \ wp_options' is marked as crashed and shoshould be retried Red
'. \ Clin003_com \ wp_options' is marked as crashed and shoshould be retried Red
'. \ Clin003_com \ wp_options' is marked as crashed and shoshould be retried Red

For the solution, refer to the above section!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.