zoukankan      html  css  js  c++  java
  • perl 分析binlog 定位错误sql 思路

    1. 获取需要的binlog 日志:
    [root@zjzc01 binlog]# mysqlbinlog --start-datetime='2016-08-01 00:00:00' --stop-datetime='2016-08-11 12:00:00' mysql-bin.00006* >a.txt
    
    
    2.获取对应行的记录 匹配 update ProductAccess
    
    [root@zjzc01 binlog]# cat get_num.pl
    open (A,"<","a.txt");
    open (B,">","b.txt");
    $a=$ARGV[0];
    $b=$ARGV[1];
     while (<A>) {
                  $num++;
                  if (( $_ =~/$as+$bs+/i ) or ($_ =~/$as+`zjzc`.`$b`s+/i) )  { $c = $num;print B ("$c
    "); };
                   }
                   }
    
    
    
      
    [root@zjzc01 binlog]# perl get_num.pl update ProductAccess
    
    
    3.
    [root@zjzc01 binlog]# cat sed.sh
     cat b.txt | while read A 
    do
    #num1=`expr $A - 5`
    num1=`expr $A - 5`
    num2=`expr $A + 5`
    #num2=`expr $A + 30`
    sed -n ''$num1','$num2'p' a.txt
    done
    
    取上下5行
    
    4.
    [root@zjzc01 binlog]# sh ./get_sql.sh update ProductAccess >aa.sql 
    [root@zjzc01 binlog]# cat aa.sql | grep 551 | grep ProductAccess
    UPDATE `zjzc`.`ProductAccess` SET `yieldForFirst`='0.0120000000' WHERE `productSn`='551'
    
    
    
    /****************
    zjtest7-frontend:/root# cat a.txt 
    UPDATE `zjzc`.`ProductAccess` SET `yieldForFirst`='0.0120000000' WHERE `productSn`='551'
    xyj
    update `zjzc`.`ProduCtAccess` SET `yieldForFirst`='0.0120000000' WHERE `productSn`='551'
    update ProduCtAccess  set 
    update ProduCtAcCess  set 
    
    zjtest7-frontend:/root# perl a1.pl  update productaccess
    zjtest7-frontend:/root# cat b.txt 
    1
    3
    4
    5
    
    
    
    
    

  • 相关阅读:
    第二天续
    使用git提交本地仓库每次需要输入账号密码的问题解决
    第二天
    开启远程之路
    第一天
    第一步了解并且安装配置
    6
    Algorithms
    Algorithms
    Algorithms
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350413.html
Copyright © 2011-2022 走看看