mysqlbinlog常用参数

首先,给出我的MySQL版本
SELECT  VERSION();
5.7.25-log
mysqlbinlog
    --database 
    --base64-output=DECODE-ROWS #如果截取出来的日志是为了SOURCE执行,不要添加这个参数
    --verbose
    --set-charset=utf8
    --skip-gtids
    --include-gtids='bec1f53c-61b9-11e9-8871-000c29d144c9:200-2302' #需要再次执行的GTID
    --exclude-gtids='bec1f53c-61b9-11e9-8871-000c29d144c9:220' #需要过滤掉的GTID
    --result-file=/var/log/mysql/dump.sql


重要参数说明
  1. --skip-gtids
    这里先给出官方文档中的说法

    Do not display any GTIDs in the output. 
    This is needed when writing to a dump file from 
    one or more binary logs containing GTIDs, 
    as shown in this example:
    shell> mysqlbinlog --skip-gtids binlog.000001 >  /tmp/dump.sql
    shell> mysqlbinlog --skip-gtids binlog.000002 >> /tmp/dump.sql
    shell> mysql -u root -p -e "source /tmp/dump.sql"
    The use of this option is otherwise not normally recommended in production. 
    

    也就是说,除了上述用法,不建议在生产环境中使用这个参数。这个参数的作用可能是规避GTID的幂等性。经过试验,发现,如果没有加这个参数,截取出来的SQL二进制日志即使被SOURCE,也不会产生效果。另外,即使在sql_log_bin=1时,如果没有加上这个参数,由于幂等性,二进制日志并不会真正执行,所以,并不会产生新的二进制日志记录。

  2. --base64-output=DECODE-ROWS
    如果加上这个参数,截取出来的日志虽然可以SOURCE成功,但是不会执行SQL。
    那么,给出结论,如果是为了查看截取出来的日志,加上这个参数和--verbose,如果是为了执行SQL,不要加这个参数。

遗留问题
  1. --idempotent

    Tell the MySQL Server to use idempotent mode while processing updates;
    this causes suppression of any duplicate-key or key-not-found errors
    that the server encounters in the current session while processing updates.
    This option may prove useful whenever it is desirable or necessary to replay one or more binary logs to a MySQL Server which may not contain all of the data to which the logs refer.
    The scope of effect for this option includes the current mysqlbinlog client and session only.

    怎么理解和使用?

  2. 加上--database就可以按照库来筛选,如何以表为精度进行筛选?

参考文档

4.6.7 mysqlbinlog — Utility for Processing Binary Log Files

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容