1. 场景
新安装的MySQL8版本作为pt-archiver归档的目标库,在执行归档操作的时候数据库连接失败,并提示如下:
DBI connect('test;host=127.0.0.1;port=33106;mysql_read_default_group=client','root',...) failed: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory at /usr/bin/pt-archiver line 2525.
2. 原因分析并解决
根据提示caching_sha2_password,初步定位是8版本的安全校验机制做了升级。官方文档查找对应的找到如下说明并提供了解决方案, MySQL8安全部分更新内容
2.1 更改用户的登录认证插件为 mysql_native_password
# 查看当前的认证插件
select user,plugin from user where user='root';
# 更改该用户的加密方式
alter user 'root'@'localhost' identified with mysql_native_password by 'Ab123654';
# 刷新生效
flush privileges;
2.2 修改配置文件并重启
# 在[mysqld]模块下添加以下配置
default_authentication_plugin=mysql_native_password
3. 总结
MySQL8加强了用户访问的安全性而默认使用了caching_sha2_password插件,习惯了5.7版本及以前的登录方式的码农们可以更改认证插件mysql_native_password,即可正常使用。