念念不忘
必会回响

MySQL修改客户端认证插件

最近看了下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

赞(0) 打赏
未经允许不得转载:堆上小栈 » MySQL修改客户端认证插件

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

登录

找回密码

注册