简体   繁体   English

无法安装 WordPress 错误:“无法连接到数据库”

[英]Cannot install WordPress error: "cannot connect to database"

Apache2 on Ubuntu, no SELinux. Ubuntu 上的 Apache2,没有 SELinux。

New server I am trying to install WordPress and I get the error新服务器 我正在尝试安装 WordPress,但出现错误

cannot connect to database

I can log in via the command line using我可以使用命令行登录

mysql -u user -p database

just fine and port 3306 is live.很好,端口 3306 处于活动状态。

root@localhost:/home/www/services.com# netstat -an root@localhost:/home/www/services.com# netstat -an

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN          
tcp6       0      0 :::80                   :::*                    LISTEN

root@localhost:/home/www/services.com# cat wp-config.php root@localhost:/home/www/services.com# cat wp-config.php

<?php

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'services.com' );

/** MySQL database username */
define( 'DB_USER', 'services.com' );

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

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

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/** define( 'AUTH_KEY',         'put your unique phrase here' ); */
/** define( 'SECURE_AUTH_KEY',  'put your unique phrase here' ); */
/** define( 'LOGGED_IN_KEY',    'put your unique phrase here' ); */
/** define( 'NONCE_KEY',        'put your unique phrase here' ); */
/** define( 'AUTH_SALT',        'put your unique phrase here' ); */
/** define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); */
/** define( 'LOGGED_IN_SALT',   'put your unique phrase here' ); */
/** define( 'NONCE_SALT',       'put your unique phrase here' ); */

define('AUTH_KEY',         'xxxxx');
define('SECURE_AUTH_KEY',  'xxxxx');
define('LOGGED_IN_KEY',    'xxxxx');
define('NONCE_KEY',        'xxxxx');
define('AUTH_SALT',        'xxxxx');
define('SECURE_AUTH_SALT', 'xxxxx');
define('LOGGED_IN_SALT',   'xxxxx');
define('NONCE_SALT',       'xxxxx');

/**#@-*/

$table_prefix = 'wp_';

define( 'WP_DEBUG', true );

/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}

/** Sets up WordPress vars and included files. */
require_once( ABSPATH . 'wp-settings.php' );

root@localhost:/home/www/services.com# ufw status root@localhost:/home/www/services.com# ufw 状态

Status: inactive

full error:完整错误:

Warning: mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in /home/www/services.com/wp-includes/wp-db.php on line 1633

Warning: mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client in /home/www/services.com/wp-includes/wp-db.php on line 1633

The server requested authentication method unknown to the client

Error establishing a database connection

This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

    Are you sure you have the correct username and password?
    Are you sure you have typed the correct hostname?
    Are you sure the database server is running?

If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

I also triple checked for whitespaces or errors in usernames and read numerous other similar post.我还三重检查了用户名中的空格或错误,并阅读了许多其他类似的帖子。

How do I get WordPress to connect to MySQL?如何让 WordPress 连接到 MySQL?

The MySQL 8 server you are using has set caching_sha2_password plugin as a default password plugin.您使用的 MySQL 8 服务器已将caching_sha2_password插件设置为默认密码插件。

(see: https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html and https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password ) (参见: https : //dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.htmlhttps://dev.mysql.com/doc/refman/8.0/en/upgrading -from-previous-series.html#upgrade-caching-sha2-password )

PHP versions before 7.1.16 or before 7.2.4 don't support caching_sha2_password . 7.1.16 或 7.2.4 之前的 PHP 版本不支持caching_sha2_password

(see: https://www.php.net/manual/en/mysqli.requirements.php ) (见: https : //www.php.net/manual/en/mysqli.requirements.php

You can temporarily fix this by using mysql_native_password for the current user by using query directly in mysql console:您可以通过直接在 mysql 控制台中使用查询为当前用户使用mysql_native_password来临时解决此问题:

ALTER USER 'services.com'@'localhost' IDENTIFIED WITH mysql_native_password BY '1111';

Or event better is to find and edit my.cnf (Linux Distros) or my.ini and change the default_authentication_plugin value to:或者更好的是找到并编辑 my.cnf (Linux Distros) 或 my.ini 并将default_authentication_plugin值更改为:

default_authentication_plugin=mysql_native_password

and restart the MySQL server.并重新启动 MySQL 服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM