mysql binlog找回數據

    • 轉自http://blog.chinaunix.net/uid-24086995-id-3218270.html
    •  
    • #開發用工具操作數據庫,誤刪除了一個表,時間大概在2012-05-18,刪除表數據後,自增字段從1開始了,判斷工具是做了truncate操作,到binlog裏面搜
       
    • -bash-3.2$ mysqlbinlog mysql-bin.000423 -vv |grep watch_list|grep truncate
       
    • truncate table `watch_lists`
       

    •  
    • #找到確實存是做了truncate操作。把BINLOG導出,找到操作的準確時間點
       
    • -bash-3.2$ mysqlbinlog mysql-bin.000423 -vv --result-file=/home/bruce/watch_list.txt
       

    •  
    • #120518 21:11:03 server id 21528 end_log_pos 273662669 Query thread_id=56426579 exec_time=1 error_code=0
       
    • SET TIMESTAMP=1337393463/*!*/;
       
    • truncate table `watch_lists`
       
    • /*!*/;
       
    • # at 273662669
       
    • #120518 21:11:03 server id 21528 end_log_pos 273662696 Xid = 15287740170
       
    • COMMIT/*!*/;
       

    •  
    • #時間點在2012-05-18 21:11:03
       
    • #需要找回的數據在備份時間點T1到這個時間點T2之間的數據。備份時間在2012-05-18 12:30:00
       

    •  
    • #把這段時間的操作記錄取出
       
    • -bash-3.2$ mysqlbinlog mysql-bin.000423 -vv --start-datetime='2012-05-18 12:30:00' --stop-datetime='2012-05-18 21:11:03' --result-file=/home/bruce/watch_list.txt
       

    •  
    • #取出SQL語句
       
    • -bash-3.2$ grep -i watch_lists watch_list.txt
       
    • INSERT INTO `watch_lists` (user_id,watch_@@@@,watch_@@@@,watch_@@@@,watch_@@@@,added_@@@@) VALUES ('13946','2','569226','@@@@','1','20120518185639')
       
    • INSERT INTO `watch_lists` (user_id,watch_@@@@,watch_@@@@,watch_@@@@,watch_@@@@,added_@@@@) VALUES ('2147','2','2841877','@@@@','1','20120518185639')

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章