[trouble shooting] mysqlbinlog unknown variable 'default-character-set=utf8'
问题描述
我的“数据目录”有很多“binary log 二进制日志”,我想要用mysqllbinlog打开看一下但报错
[root@centos7 data]# ../bin/mysqlbinlog mysql-bin.index
../bin/mysqlbinlog: unknown variable 'default-character-set=utf8'
解决过程
因为“binary log 二进制日志” 记录了对于修改数据的每一个动作,比如插入一行中文字段,既然设置到中文就需要用utf8或者gbk编码才能正确阅读,所以mysqlbinlog首先需要查看my.cnf文件的“charactset 字符集”是怎样设置的才去打开“二进制日志”,其实就是用某种character set来打开一堆“0101010”的二进制文件
谷歌很多的答案是把"my.cnf 配置文件"中,“mysqld服务器”的字符集编码修改一下
因为 --default-character-set的写法,在MySQL 5.53版本已经”去除了“,不赞成用这种写法,应该使用 “--character-set-server
” 替换掉
但其实真正问题,不是“mysqld 服务端”的编码,而是my.cnf中“client 客户端”的编码集,不能被mysqlbinlog识别,然而【client】只有一种 “default-character-set” 的写法, 不可能用“--character-set-server
” 去替换的可能性
解决方法可以把它注释掉,重启mysqld, 这样能够让 mysqlbinlog正常工作,但是失去了“客户端client”使用字符集的功能
[root@centos7 data]# ../bin/mysqlbinlog mysql-bin.000014
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#160108 13:45:19 server id 1 end_log_pos 107 Start: binlog v 4, server v 5.5.47-log created 160108 13:45:19 at startup
ROLLBACK/*!*/;
BINLOG '
70yPVg8BAAAAZwAAAGsAAAAAAAQANS41LjQ3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAADvTI9WEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
'/*!*/;
# at 107
#160108 15:27:43 server id 1 end_log_pos 126 Stop
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
最好的办法是,不去动my.cnf文件,让它保持原来的样子
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
default-character-set=utf8
在mysqlbinlog的选项中下工夫
1.让mysqlbinlog不要去读"my.cnf"
2.让mysqlbinlog使用utf8的方式去打开“二进制日志”
各种option详细参考document:mysqlbinlog — Utility for Processing Binary Log Files
[root@centos7 data]# ../bin/mysqlbinlog --no-defaults --set-charset=utf8 mysql-bin.000014
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
DELIMITER /*!*/;
# at 4
#160108 13:45:19 server id 1 end_log_pos 107 Start: binlog v 4, server v 5.5.47-log created 160108 13:45:19 at startup
ROLLBACK/*!*/;
BINLOG '
70yPVg8BAAAAZwAAAGsAAAAAAAQANS41LjQ3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAADvTI9WEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
'/*!*/;
# at 107
#160108 15:27:43 server id 1 end_log_pos 126 Stop
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
同时这样的打开方式不用重启MySQL服务器