WordPress与MySQL报错:服务器请求客户端未知的认证方式
Hey, I’ve dealt with this exact headache before—let me break down what’s going on and how to fix it quickly:
Why this error happens
MySQL 8.0 switched its default authentication plugin to caching_sha2_password, which is more secure but isn’t supported by older PHP 7.x MySQLi extensions. That’s why your WordPress can’t connect, even when you use a "safe" password or enter the wrong one (the error is about the authentication method, not the password itself).
Your earlier attempt with old_passwords=1 failed because that setting was removed in MySQL 8.0—it’s only for super old MySQL versions (pre-5.6), so adding it breaks the service entirely.
Step-by-step fix
Here’s what you need to do to get WordPress connecting properly:
Log into MySQL as root
Open your terminal/command prompt and run:mysql -u root -pEnter your root password when prompted.
Check your WordPress database user’s authentication plugin
Replacewp_userwith the actual username you created for WordPress, then run:SELECT user, host, plugin FROM mysql.user WHERE user = 'wp_user';You’ll see
pluginset tocaching_sha2_password—that’s the culprit.Update the user to use the compatible authentication plugin
Replacewp_user,localhost(use%if your WordPress is on a different server), andyour_secure_passwordwith your details:ALTER USER 'wp_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_secure_password';Flush MySQL privileges
Run this to make sure the changes take effect immediately:FLUSH PRIVILEGES;Restart your MySQL service
- On Windows: Open Services, find MySQL, right-click and select "Restart"
- On Linux: Run
sudo systemctl restart mysql
Test the WordPress connection
Go back to your WordPress setup page, enter the updated credentials (username, new password, database name), and it should connect without the authentication error.
Quick note for future reference
If you ever upgrade PHP to 7.4 or later, those versions do support caching_sha2_password—so you can switch the user back to that plugin for better security once you’re on a newer PHP version.
内容的提问来源于stack exchange,提问作者tinashe.chipomho

