使用Percona Toolkit的工具连接MySQL 8.x数据库时,会遇到类似”failed: Plugin caching_sha2_password could not be loaded: lib64/mariadb/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory at /usr/bin/pt-show-grants line 1367“这样的错误,如下案例所示:
#pt-find --ctime +2 --engine InnoDB -u monitor --ask-passEnter password:DBI connect(';;mysql_read_default_group=client','monitor',...) failed: Plugin caching_sha2_password could not be loaded: lib64/mariadb/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory at /usr/bin/pt-find line 323.
遇到这个错误是因为MySQL 8.0(8.0.4)引入了caching_sha2_password插件并将其作为默认的身份验证插件,而当前Percona Toolkit(Percona Toolkit 3.2.1是当前最新版本)的工具依赖的MySQL驱动程序尚不支持caching_sha2_password这这种身份验证,所以报这个错误。例如pt-find使用的驱动为MySQL driver for Perl (DBD::mysql)(perl-DBD-MySQL)
解决方案:
1:更改用户的密码插件为mysql_native_password
mysql> select user,host ,plugin from mysql.user where user='monitor';+---------+-----------+-----------------------+| user | host | plugin |+---------+-----------+-----------------------+| monitor | localhost | caching_sha2_password |+---------+-----------+-----------------------+1 row in set (0.00 sec)mysql> alter user monitor@'localhost' identified with mysql_native_password by '************';Query OK, 0 rows affected (0.07 sec)
这种方法就是让MySQL使用mysql_native_password插件认证密码,这些驱动自然支持这种方式连接MySQL数据库。
2:修改MySQL的全局配置
在my.cnf配置文件中设置default_authentication_plugin=mysql_native_password 后重启MySQL数据库实例。这是一种不太安全的做法,按理说只需修改Percona Toolkit的工具使用的账号即可。但是这种方法修改的是MySQL的全局配置。影响范围扩大,不推荐使用
[mysqld]
default_authentication_plugin=mysql_native_password
3:更新驱动
MySQL 8.0.4开始默认使用caching_sha2_password作为身份验证插件. caching_sha2_password和 sha256_password认证插件提供比mysql_native_password插件更安全的密码加密方式 ,并且使用caching_sha2_password的性能比sha256_password更好。如果我们修改用户的密码插件为mysql_native_password,似乎有点开倒车的感觉。其实这个问题也好解决,如果我们想用新的密码验证方式,那么我们可以安装高版本的驱动。这些驱动支持这种方式。
如下所示,当前测试环境,perl-DBD-MySQL模块依赖的类库为/usr/lib64/mysql/libmysqlclient.so.18。在CentOS/RHEL/OL 7上,默认情况下,perl-DBD-MySQL要么链接到旧版本的mariadb-libs(5.5),或链接mysql-community-libs-compat下的类库。
[root@KerryDB ~]# more /etc/redhat-releaseCentOS Linux release 7.5.1804 (Core)[root@KerryDB ~]# ldd /usr/lib64/perl5/vendor_perl/auto/DBD/mysql/mysql.so | grep 'mysql\|maria'libmysqlclient.so.18 => /usr/lib64/mysql/libmysqlclient.so.18 (0x00007f48b0724000)[root@KerryDB ~]# rpm -qf /usr/lib64/mysql/libmysqlclient.so.18mysql-community-libs-compat-8.0.18-1.el7.x86_64
此版本(libmysqlclient.so.18)不支持新的身份验证插件。至少需要有libmysqlclient.so.21或libmariadb.so.3 或以上版本的类库才支持caching_sha2_password认证方式。 所以,我可以下载博客Perl & MySQL 8.0中的perl-DBD-MySQL-4.044-1.el7_.x86_64.zip 或perl-DBD-MySQL-4.050-1.el7.x86_64.rpm组件。
https://lefred.be/wp-content/uploads/2019/06/perl-DBD-MySQL-4.044-1.el7_.x86_64.zip
https://lefred.be/wp-content/uploads/2020/08/perl-DBD-MySQL-4.050-1.el7.x86_64.rpm
具体安装过程如下, 安装完成后,Percona Tookkit就能正常连接MySQL 8了
[root@KerryDB tmp]# rpm -ivh perl-DBD-MySQL-4.044-1.el7.x86_64.rpm #此处报冲突,因为 perl-DBD-MySQL-4.023-6.el7.x86_64与perl-DBD-MySQL-4.044-1.el7.x86_64.rpm冲突了。Preparing... ################################# [100%]file /usr/lib64/perl5/vendor_perl/Bundle/DBD/mysql.pm from install of perl-DBD-MySQL-4.044-1.el7.x86_64 conflicts with file from package perl-DBD-MySQL-4.023-6.el7.x86_64file /usr/lib64/perl5/vendor_perl/DBD/mysql.pm from install of perl-DBD-MySQL-4.044-1.el7.x86_64 conflicts with file from package perl-DBD-MySQL-4.023-6.el7.x86_64file /usr/lib64/perl5/vendor_perl/DBD/mysql/GetInfo.pm from install of perl-DBD-MySQL-4.044-1.el7.x86_64 conflicts with file from package perl-DBD-MySQL-4.023-6.el7.x86_64file /usr/lib64/perl5/vendor_perl/DBD/mysql/INSTALL.pod from install of perl-DBD-MySQL-4.044-1.el7.x86_64 conflicts with file from package perl-DBD-MySQL-4.023-6.el7.x86_64file /usr/lib64/perl5/vendor_perl/auto/DBD/mysql/mysql.so from install of perl-DBD-MySQL-4.044-1.el7.x86_64 conflicts with file from package perl-DBD-MySQL-4.023-6.el7.x86_64file /usr/share/man/man3/Bundle::DBD::mysql.3pm.gz from install of perl-DBD-MySQL-4.044-1.el7.x86_64 conflicts with file from package perl-DBD-MySQL-4.023-6.el7.x86_64file /usr/share/man/man3/DBD::mysql.3pm.gz from install of perl-DBD-MySQL-4.044-1.el7.x86_64 conflicts with file from package perl-DBD-MySQL-4.023-6.el7.x86_64file /usr/share/man/man3/DBD::mysql::INSTALL.3pm.gz from install of perl-DBD-MySQL-4.044-1.el7.x86_64 conflicts with file from package perl-DBD-MySQL-4.023-6.el7.x86_64[root@KerryDB tmp]# rpm -Uvh perl-DBD-MySQL-4.044-1.el7.x86_64.rpmPreparing... ################################# [100%]Updating / installing...1:perl-DBD-MySQL-4.044-1.el7 ################################# [ 50%]Cleaning up / removing...2:perl-DBD-MySQL-4.023-6.el7 ################################# [100%][root@KerryDB tmp]#
当然,我们也可以下载源码安装,下载地址如下,但是最好使用cpan安装(cpan -f DBD::mysql),如果手工安装的话,各种依赖项缺少,会让你抓狂! 下面是我的一个源码安装的折腾过程。
https://cpan.metacpan.org/authors/id/D/DV/DVEEDEN/
从如下链接下载了DBD-mysql-4.050.tar.gz
https://cpan.metacpan.org/authors/id/D/DV/DVEEDEN/DBD-mysql-4.050.tar.gz
# tar -xzvf DBD-mysql-4.050.tar.gz# cd DBD-mysql-4.050# perl Makefile.PLCan't locate Devel/CheckLib.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 12.BEGIN failed--compilation aborted at Makefile.PL line 12.
如上所示,遇到这个错误,是因为没有安装perl-Devel-CheckLib包,缺少相关依赖组件。在安装包的文件META.json中,你就可以看到安装这个需要安装哪些组件。如下截图所示:
[root@KerryDB DBD-mysql-4.050]# yum list | grep "perl-Devel-CheckLib"perl-Devel-CheckLib.noarch 0.99-2.el7 base[root@KerryDB DBD-mysql-4.050]# yum list installed | grep "perl-Devel-CheckLib"[root@KerryDB DBD-mysql-4.050]# yum install perl-Devel-CheckLib
接下来又遇到了“Can't exec "mysql_config": No such file or directory at Makefile.PL line 89”这个错误
[root@KerryDB DBD-mysql-4.050]# perl Makefile.PLCan't exec "mysql_config": No such file or directory at Makefile.PL line 89.Cannot find the file 'mysql_config'! Your execution PATH doesn't seemnot contain the path to mysql_config. Resorting to guessed values!PLEASE NOTE:For 'make test' to run properly, you must ensure that thedatabase user 'root' can connect to your MySQL serverand has the proper privileges that these tests require suchas 'drop table', 'create table', 'drop procedure', 'create procedure'as well as others.mysql> grant all privileges on test.* to 'root'@'localhost' identified by 's3kr1t';You can also optionally set the user to run 'make test' with:perl Makefile.PL --testuser=usernameCan't exec "mysql_config": No such file or directory at Makefile.PL line 603.Can't find mysql_config. Use --mysql_config option to specify where mysql_config is locatedFailed to determine directory of mysql.h. Useperl Makefile.PL --cflags=-I
查一下相关资料,解决这个问题要么安装libmysqlclient-dev,要么在系统中查找mysql_config文件,在源码安装过程中加上参数选项(如下所示),具体情况根据你的环境而定,有可能你在源码安装过程还会遇到不同的错误。
# perl Makefile.PL --mysql_config=/usr/bin/mysql_config_editor#make#make test#make install
参考资料:
https://lefred.be/content/perl-mysql-8-0/
https://www.percona.com/doc/percona-monitoring-and-management/2.x/manage/conf-mysql-ps8.html