最近看了下MySQL的error.log日志文件,发现只要链接数据库就会出现如下日志:
2025-12-16T07:24:09.205402Z 25 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
2025-12-16T07:24:10.783194Z 26 [Warning] [MY-013360] [Server] Plugin mysql_native_password reported: ''mysql_native_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
看来需要将认证插件替换为caching_sha2_password。本次更新步骤如下:
1、更新客户端认证插件
使用root用户登录到mysql后,先确认那些用户使用了mysql_native_password。
SELECT user, host, plugin FROM mysql.user
为了避免修改多处密码,建议将密码,主机保持一致。
ALTER USER 'mysql用户名'@'%' IDENTIFIED WITH caching_sha2_password BY 'mysql密码';
-- 刷新权限
FLUSH PRIVILEGES;
-- 检查用户是否更新
SELECT user, host, plugin FROM mysql.user where user = 'mysql用户名'
2、更新MySQL服务
只修改用户能解决一时的问题,想要避免后续通过默认创建用户使用到mysql_native_password,还需要修改MySQL服务。
编辑 MySQL 配置文件: 找到您的 MySQL 配置文件(通常是/etc/my.cnf 或/etc/mysql/my.cnf)修改为如下:
[mysqld]
# 确保服务器默认使用更安全的插件
default_authentication_plugin=caching_sha2_password
重新启动MySQL 。
sudo systemctl restart mysql






