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
    
    
    
    
    

  • 相关阅读:
    【SpringBoot框架学习】yml/yaml语法 详解
    【SpringBoot框架学习】搭建开发环境 详解
    【SpringBoot框架学习】热部署 的配置 详解
    JVM-类加载机制
    JVM-字节码
    JVM-垃圾收集
    JVM-体系结构
    HTTP-报文结构
    TCP-四次挥手
    TCP-三次握手
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6199387.html
Copyright © 2011-2022 走看看