"Error establishing a database connection" 在 macOS 上配置 Wordpress + mysql 8.0x + nginx

"Error establishing a database connection" when config Wordpress + mysql 8.0x + nginx on macOS

我在 macOS 上设置 wordpress 时遇到“建立数据库连接时出错”的问题。 这是我的步骤:

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

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

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

/** 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', '' );
$ sudo mysql -u admin -p
mysql> CREATE DATABASE db_name;
mysql> CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'db_pass';
mysql> GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> exit
$ sudo mysql.server restart
$ sudo nginx // start nginx 

哪位有经验的,请帮帮我, 谢谢

终于找到解决方法了

  • 在 mysql 8.0x 中,使用 mysql> CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'db_pass'; 创建用户会将身份验证类型指定为 'caching_sha2_password'.

  • 我只是将创建用户的命令更改为 mysql> CREATE USER 'db_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'db_pass';

现在我的 wordpress 网站可以完美运行了。