报错场景
WordPress 提示 "建立数据库连接失败"。打开 WordPress 的调试模式,查看详情报错原因。
wp-config.php
里的代码修改为:
define('WP_DEBUG', true);
如果具体的报错原因是:
ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
说明 MySQL 客户端不支持 MySQL8 的新的加密验证方式 caching_sha2_password
。
解决方法
A)临时解决,修改用户的密码为老的加密方式:
ALTER USER myuser IDENTIFIED WITH mysql_native_password BY 'mypassword';
B)修改 MySQL 默认的加密方式:
$ sudo cp /etc/my.cnf /etc/my.cnf.backup.20181027.001
$ sudo nano /etc/my.cnf
在 [mysqld] 区块加入以下内容:
[mysqld]
default_authentication_plugin=mysql_native_password
重启 MySQL:
$ sudo systemctl restart mysqld
参考文章:
How to fix Wordpress database connection for MySQL 8
How to change caching_sha2_password to mysql_native_password on a DigitalOcean's Managed MySQL Database? | DigitalOcean