查詢數(shù)據(jù)庫相關(guān)配置參數(shù)
創(chuàng)新互聯(lián)長期為上千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為康保企業(yè)提供專業(yè)的成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè),康保網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。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 https://files.pythonhosted.org/packages/8a/e9/8468cd68b582b06ef554be0b96b59f59779627131aad48f8a5bce4b13450/wheel-0.29.0-py2.py3-none-any.whl (66kB) 100% |████████████████████████████████| 71kB 103kB/s Collecting mysql-replication==0.13 (from -r requirements.txt (line 3)) Downloading /tupian/20230522/mysql-replication-0.13.tar.gz 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
創(chuàng)建測試數(shù)據(jù),并執(zhí)行誤刪除
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)
查看二進(jìn)制日志文件
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)
解析出標(biāo)準(zhǔn)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
網(wǎng)站欄目:MySQL使用binlog2sql閃回誤刪除數(shù)據(jù)-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://www.rwnh.cn/article40/ceceeo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、關(guān)鍵詞優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、建站公司、網(wǎng)站建設(shè)、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容