zoukankan      html  css  js  c++  java
  • mysqlbinlog读懂binlog

    binlog 报unknown variable 'default-character-set=utf8'

    方法1: 在/etc/my.cnf 中将default-character-set=utf8修改成charater-set-server=utf8
    方法2: mysqlbinlog --no-defaults mysql-bin.000001

    SHOW SLAVE STATUS:

    1) The position, ON THE MASTER, from which the I/O thread is reading: Master_Log_File/Read_Master_Log_Pos. —–相对于主库,从库读取主库的二进制日志的位置,是IO线程

    2) The position, IN THE RELAY LOGS, at which the SQL thread is executing: Relay_Log_File/Relay_Log_Pos —-相对于从库,是从库的sql线程执行到的位置

    3) The position, ON THE MASTER, at which the SQL thread is executing:Relay_Master_Log_File/Exec_Master_Log_Pos —-相对于主库,是从库的sql线程执行到的位置


    读懂binlog日志:
    binlog-format=ROW模式下:

    1、提取sakila库的binlog日志
    mysqlbinlog -d sakila --base64-output=decode-rows -v binlog.000008 >/tmp/test.sql

    2、提取sakila库下actor表的binlog日志
    mysqlbinlog -d sakila --base64-output=decode-rows -v binlog.000008|grep actor

    mysqlbinlog -d sakila --base64-output=decode-rows -v mysql-bin.000008|grep -C 10 actor> /tmp/actor.txt

    ###grep -A -B -C 后面都跟阿拉伯数字 

    -A是显示匹配后和它后面的n行。 
    -B是显示匹配行和它前面的n行。 
    -C是匹配行和它前后各n行。 
    -C覆盖面最大,这3个开关都是关于匹配行的上下文的(context

    ###

    筛选UPDATE

    cat /tmp/actor.txt |grep -C 10 UPDATE > /tmp/actor_update.txt

    3、提取sakila库下INSERT操作的binlog日志
    mysqlbinlog -d sakila --base64-output=decode-rows -v binlog.000008|grep insert

    4、提取指定时间段的binlog日志
    mysqlbinlog --base64-output=decode-rows -v --start-datetime='2016-01-04 15:10:00' --stop-datetime='2016-01-04 15:11:00' binlog.000008 >/tmp/test.sql
    提取指定position位置的binlog日志
    mysqlbinlog --base64-output=decode-rows -v --start-position='398' --stop-position='617' binlog.000008 >/tmp/test.sql

    5、提取指定position位置的binlog日志并输出到压缩文件
    mysqlbinlog --start-position="6088" --stop-position="9832" binlog.000008 |gzip >test.sql.gz

    6、提取指定position位置的binlog日志导入数据库
    mysqlbinlog --start-position="120" --stop-position="332" binlog.000008 | mysql -uroot -p

    7、提取指定开始时间的binlog并输出到日志文件
    mysqlbinlog --start-datetime="2018-12-15 20:15:23" binlog.000008 --result-file=test.sql

    8、提取指定位置的多个binlog日志文件
    mysqlbinlog --start-position="120" --stop-position="332" binlog.000008 binlog.000008|more

    9、提取指定数据库binlog并转换字符集到UTF8
    mysqlbinlog --database=test --set-charset=utf8 binlog.000008 binlog.000008 >test.sql

    10、远程提取日志,指定结束时间
    mysqlbinlog -uroot -p -h10.168.10.11 -P3306 --stop-datetime="2014-12-15 20:30:23" --read-from-remote-server mysql-bin.000033 |more

    11、远程提取使用row格式的binlog日志并输出到本地文件
    mysqlbinlog -uroot -p -P3606 -h10.168.10.11 --read-from-remote-server -vv binlog.000008 >test.sql

  • 相关阅读:
    centos7安装sshd
    Linux搭建redist-cluster集群
    nginx离线安装,反向代理,负载均衡
    2017/12/31Java基础学习——数组输出の通过Arrays.toString()方法
    Java代码编写规范
    2017/12/27java基础学习——遇到的不懂问题
    2017/12/23Java基础学习——如何通过记事本编写代码,并通过dos界面运行Java源文件
    ZOJ3880 Demacia of the Ancients【序列处理+水题】
    ZOJ3869 Ace of Aces【序列处理】
    ZOJ3872 Beauty of Array【DP】
  • 原文地址:https://www.cnblogs.com/elontian/p/9202603.html
Copyright © 2011-2022 走看看