MySQL使用binlog2sql閃回誤刪除資料
查詢資料庫相關配置引數
root [test]> show global variables like 'binlog%format%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set (0.00 sec) root [test]> show global variables like 'binlog%row%image%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | binlog_row_image | FULL | +------------------+-------+ 1 row in set (0.00 sec) root [test]> show global variables like '%log%bin%'; +----------------------------------+-----------------------------------------------+ | Variable_name | Value | +----------------------------------+-----------------------------------------------+ | log_bin | ON | | log_bin_basename | /data1/mysql_log_23306/binlog/mysql-bin | | log_bin_index | /data1/mysql_log_23306/binlog/mysql-bin.index | | log_bin_trust_function_creators | ON | | log_bin_use_v1_row_events | OFF | | log_statements_unsafe_for_binlog | ON | +----------------------------------+-----------------------------------------------+ 6 rows in set (0.01 sec)
安裝binlog2sql
正克隆到 'binlog2sql'... remote: Counting objects: 298, done. remote: Compressing objects: 100% (4/4), done. remote: Total 298 (delta 0), reused 1 (delta 0), pack-reused 294 接收物件中: 100% (298/298), 147.01 KiB | 49.00 KiB/s, done. 處理 delta 中: 100% (151/151), done. [root@mysql-server binlog2sql]# source ../venv4archer/bin/activate (venv4archer) [root@mysql-server binlog2sql]# pip install -r requirements.txt Requirement already satisfied: PyMySQL==0.7.11 in /data1/venv4archer/lib/python3.6/site-packages (from -r requirements.txt (line 1)) (0.7.11) Collecting wheel==0.29.0 (from -r requirements.txt (line 2)) Cache entry deserialization failed, entry ignored Downloading (66kB) 100% |████████████████████████████████| 71kB 103kB/s Collecting mysql-replication==0.13 (from -r requirements.txt (line 3)) Downloading Building wheels for collected packages: mysql-replication Running setup.py bdist_wheel for mysql-replication ... done Stored in directory: /root/.cache/pip/wheels/91/33/05/32b16ccadd4fc566ff38af96afdeb5d57d49c2f1eff0402164 Successfully built mysql-replication Installing collected packages: wheel, mysql-replication Found existing installation: wheel 0.31.1 Uninstalling wheel-0.31.1: Successfully uninstalled wheel-0.31.1 Successfully installed mysql-replication-0.13 wheel-0.29.0
建立測試資料,並執行誤刪除
root [(none)]> flush logs; Query OK, 0 rows affected (0.00 sec) root [(none)]> use test Database changed root [test]> create table user(id int(12) unsigned auto_increment comment 'id' primary key, name varchar(15), add_time timestamp); Query OK, 0 rows affected (0.01 sec) root [test]> insert into user(name, add_time) values('neo', '2018-09-01'), ('trinity', '2018-09-02'), ('jason', '2018-09-05'); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 root [test]> delete from user where add_time < '2018-09-05'; Query OK, 2 rows affected (0.01 sec)
檢視二進位制日誌檔案
root [test]> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000002 | 2236 | | mysql-bin.000003 | 201 | | mysql-bin.000004 | 1218 | +------------------+-----------+ 3 rows in set (0.00 sec)
解析出標準SQL
(venv4archer) [root@mysql-server binlog2sql]# python binlog2sql/binlog2sql.py -uroot -p'root' -h 127.0.0.1 -P 23306 -dtest -tuser --start-file='mysql-bin.000004' --start-datetime='2018-09-14 17:00:00' --stop-datetime='2018-09-14 18:25:00' > /tmp/20180914_raw.sql (venv4archer) [root@mysql-server binlog2sql]# cat /tmp/20180914_raw.sql USE b'test'; create table user(id int(12) unsigned auto_increment comment 'id' primary key, name varchar(15), add_time timestamp); INSERT INTO `test`.`user`(`id`, `name`, `add_time`) VALUES (1, 'neo', '2018-09-01 00:00:00'); #start 411 end 824 time 2018-09-14 18:22:33 INSERT INTO `test`.`user`(`id`, `name`, `add_time`) VALUES (2, 'trinity', '2018-09-02 00:00:00'); #start 411 end 824 time 2018-09-14 18:22:33 INSERT INTO `test`.`user`(`id`, `name`, `add_time`) VALUES (3, 'jason', '2018-09-05 00:00:00'); #start 411 end 824 time 2018-09-14 18:22:33 DELETE FROM `test`.`user` WHERE `id`=1 AND `name`='neo' AND `add_time`='2018-09-01 00:00:00' LIMIT 1; #start 855 end 1187 time 2018-09-14 18:23:31 DELETE FROM `test`.`user` WHERE `id`=2 AND `name`='trinity' AND `add_time`='2018-09-02 00:00:00' LIMIT 1; #start 855 end 1187 time 2018-09-14 18:23:31
解析出回滾SQL
(venv4archer) [root@mysql-server binlog2sql]# python binlog2sql/binlog2sql.py -uroot -p'root' -h 127.0.0.1 -P 23306 -dtest -tuser --start-file='mysql-bin.000004' --start-datetime='2018-09-14 17:00:00' --stop-datetime='2018-09-14 18:25:00' -B > /tmp/20180914_rollback.sql (venv4archer) [root@mysql-server binlog2sql]# cat //tmp/20180914_rollback.sql INSERT INTO `test`.`user`(`id`, `name`, `add_time`) VALUES (2, 'trinity', '2018-09-02 00:00:00'); #start 855 end 1187 time 2018-09-14 18:23:31 INSERT INTO `test`.`user`(`id`, `name`, `add_time`) VALUES (1, 'neo', '2018-09-01 00:00:00'); #start 855 end 1187 time 2018-09-14 18:23:31 DELETE FROM `test`.`user` WHERE `id`=3 AND `name`='jason' AND `add_time`='2018-09-05 00:00:00' LIMIT 1; #start 411 end 824 time 2018-09-14 18:22:33 DELETE FROM `test`.`user` WHERE `id`=2 AND `name`='trinity' AND `add_time`='2018-09-02 00:00:00' LIMIT 1; #start 411 end 824 time 2018-09-14 18:22:33 DELETE FROM `test`.`user` WHERE `id`=1 AND `name`='neo' AND `add_time`='2018-09-01 00:00:00' LIMIT 1; #start 411 end 824 time 2018-09-14 18:22:33
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2214227/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL誤刪資料?試試資料閃回工具binlog2sqlMySql
- mysql閃回工具binlog2sqlMySql
- 利用binlog2sql閃回丟失資料SQL
- MySQL工具之binlog2sql閃回操作MySql
- mysql資料誤刪後的資料回滾MySql
- mysql資料庫誤刪除操作說明MySql資料庫
- MySQL資料庫表誤刪除恢復(一)MySql資料庫
- Flashback Drop閃回刪除功能實踐
- MySQL刪除資料表MySql
- MySQL閃回技術之binlog2sql恢復binlog中的SQLMySql
- 【Flashback】Flashback Drop閃回刪除功能實驗
- 誤刪除資料了怎麼辦?小編交易誤刪除資料的恢復方法
- mysql誤刪資料恢復MySql資料恢復
- 【北亞資料恢復】誤刪除oracle表和誤刪除oracle表資料的資料恢復方法資料恢復Oracle
- 【HBase】誤刪除資料怎麼辦?
- Web開發經驗(1)防止MySQL資料庫誤更新/刪除WebMySql資料庫
- mysql 誤刪除表內資料,透過binlog日誌恢復MySql
- 誤刪除儲存SqlServer資料庫資料恢復SQLServer資料庫資料恢復
- MySQL超大表刪除資料過程MySql
- Mysql 誤刪資料進行恢復MySql
- Oracle資料庫閃回Oracle資料庫
- flashback query閃回資料
- 資料檔案誤刪除(DM_單機)
- 恢復Oracle資料庫誤刪除資料的語句Oracle資料庫
- Oracle閃回技術 為Oracle閃回配置資料庫Oracle資料庫
- mysql 刪除表中重複的資料MySql
- MySQL 批量更新、刪除資料shell指令碼MySql指令碼
- 使用binlog2sql恢復資料SQL
- 刪除資料
- 誤刪除ESXi虛擬機器資料恢復虛擬機資料恢復
- 聊聊PG資料庫的防誤刪除問題資料庫
- whk我【資料刪除】你個【資料刪除】的
- 簡單介紹mysql如何刪除資料表和關聯的資料表刪除詳情MySql
- Mysql資料庫delete刪除後資料恢復報告MySql資料庫delete資料恢復
- 如何刪除資料庫下的所有表(mysql)資料庫MySql
- 6、MySQL刪除資料庫(DROP DATABASE語句)MySql資料庫Database
- MySQL 中刪除的資料都去哪兒了?MySql
- LINUX下資料被誤刪除、LINUX下資料被誤格式化後資料恢復Linux資料恢復