mysql二进制日志

fyh 2022年05月14日 56次浏览

基于段的格式binlog_format=STATEMENT

show variables like 'binlog_format';
set session binlog_format=statement;
show binary logs;
flush logs;
show variables like 'binlog_row_image';
# 查看是否是从库
show slave status\G;
# 查看
mysqlbinlog 日志名

优点:
日志记录量相对较小,节约磁盘和网络IO
只对一条记录修改和插入时,row格式所产生的日志量小于段产生的日志量
缺点:
必须记录上下文信息,确保在从服务器上执行结果和主服务器上一致
非确定性函数无法复制,如uuid()

基于行的格式

binlog_format=ROW
优点:
使MySQL主从复制更加安全
对每行数据的修改比基于段的高效
缺点:
记录日志量大binlog_row_image=[FULL|MINIMAL|NOBLOB] FULL默认值

混合模式

binlog_format=mixed
根据sql语句由系统决定,大小由sql决定

出于性能考虑建议:mixed和row(minimal)
综合考虑:https://segmentfault.com/a/1190000016008847