Не удается установить ошибку WordPress: «не удается подключиться к базе данных» - PullRequest
1 голос
/ 10 марта 2020

Apache2 в Ubuntu, нет SE Linux.

Новый сервер Я пытаюсь установить WordPress и получаю ошибку

cannot connect to database

Я могу войти через командную строку, используя

mysql -u user -p database

просто отлично, и порт 3306 работает.

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

<?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

Status: inactive

полная ошибка:

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.

Я также трижды проверил наличие пробелов или ошибок в именах пользователей и прочитал множество других подобных постов.

Как мне получить WordPress для подключения к MySQL?

1 Ответ

2 голосов
/ 10 марта 2020

Используемый вами сервер MySQL 8 установил плагин caching_sha2_password в качестве плагина пароля по умолчанию.

(см .: https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html и https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade -caching-sha2-password )

PHP версии до 7.1.16 или до 7.2.4 не поддерживает caching_sha2_password.

(см .: https://www.php.net/manual/en/mysqli.requirements.php)

Вы можете временно исправить это, используя mysql_native_password для текущего пользователя, используя запрос непосредственно в консоли mysql:

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

Или лучше найти и отредактировать my.cnf (Linux Distros) или my.ini и изменить значение default_authentication_plugin на:

default_authentication_plugin=mysql_native_password

и перезапустить MySQL сервер.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...