pt-duplicate-key-checker报Wide character in print at xxx错误总结
使用Percona Toolkit的pt-duplicate-key-checker工具时,偶尔会遇到"Error checking xxx: Wide character in print at /usr/bin/pt-duplicate-key-checker line 5248."这类错误。如下例子所示
$ pt-duplicate-key-checker -hlocalhost -P7306 -uroot -pxxxxxx --socket /tmp/mysql.sock
# ########################################################################
# kerry.employee
# ########################################################################
# ix_employee_n2 is a duplicate of ix_employee_n1
# Key definitions:
# KEY `ix_employee_n2` (`employee_name`)
# KEY `ix_employee_n1` (`employee_name`),
# Column types:
Error checking kerry.employee: Wide character in print at /usr/bin/pt-duplicate-key-checker line 5248.
.........................................................................
.........................................................................
遇到这个错误,是因为perl程序中处理中文等宽字符时,perl不能识别要处理的内容。所以你必须使用参数--charset指定字符集为utf8,才能避免这个错误。如下所示
$ pt-duplicate-key-checker -hlocalhost -P7306 -uroot --ask-pass --socket /tmp/mysql.sock --charset=utf8
Enter password:
# ########################################################################
# kerry.employee
# ########################################################################
# ix_employee_n2 is a duplicate of ix_employee_n1
# Key definitions:
# KEY `ix_employee_n2` (`employee_name`)
# KEY `ix_employee_n1` (`employee_name`),
# Column types:
# `employee_name` varchar(30) collate utf8mb4_general_ci default null comment '员工姓名'
# To remove this duplicate index, execute:
ALTER TABLE `kerry`.`employee` DROP INDEX `ix_employee_n2`;
小知识点:
在 Perl看来, 字符串只有两种形式. 一种是octets, 即8位序列, 也就是我们通常说的字节数组. 另一种utf8编码的字符串, Perl管它叫string. 也就是说: Perl只熟悉两种编码: Ascii(octets)和utf8(string).Perl只能处理两种编码:ascii码和utf-8。ascii码是很少的,像中文、日文、韩文等字符要想能被perl处理,只能用utf-8编码方式。