查看mysql的binlog日志内容

avatar 2020年6月9日18:01:50 评论 1,893 次浏览

mysql的binlog日志是二进制的,如果我们直接食用cat或者vim打开是乱码,无法直观的看到mysql的日志中打印的语句,所以必须使用mysqlbinlog命令打开binlog日志,才能查看日志内容,开启日志方法参考:https://www.wulaoer.org/?p=1267

[root@www.wulaoer.org ~]# cd /usr/local/mysql/
[root@www.wulaoer.org mysql]# ./bin/mysqlbinlog /usr/local/mysql/var/mysql-bin.000013 
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#200507 13:33:32 server id 1  end_log_pos 123 CRC32 0xb3e430b4  Start: binlog v 4, server v 5.7.26-log created 200507 13:33:32 at startup
ROLLBACK/*!*/;
BINLOG '
rJ2zXg8BAAAAdwAAAHsAAAAAAAQANS43LjI2LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAACsnbNeEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
AbQw5LM=
'/*!*/;
# at 123
#200507 13:33:32 server id 1  end_log_pos 154 CRC32 0xda2fcb02  Previous-GTIDs
# [empty]
# at 154
#200530 19:58:32 server id 1  end_log_pos 177 CRC32 0x44c7b31e  Stop
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

打开报错

如果直接使用mysqlbinlog打开日志报错,

[root@www.wulaoer.org mysql]# ./bin/mysqlbinlog /usr/local/mysql/var/mysql-bin.000013
mysqlbinlog: unknown variable 'default-character-set=utf8mb4'

解决方法:

1、在mysql配置文件/etc/my.cnf中将default-character-set=utf8 修改为 character-set-server = utf8,然后重启mysql,这样对以前的产生的mysql日志无法改变,而且代价太大。不推荐

2、在mysqlbinlog后面加参数--no-defaults

[root@www.wulaoer.org mysql]# ./bin/mysqlbinlog --no-defaults /usr/local/mysql/var/mysql-bin.000013

可根据自己需求选择不同的方法。如果把binlog日志在mysql中运行一边哪就需要学习下一个章节了,期待一下吧

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: