您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關怎么用mysqlbinlog做基于時間點的數據恢復,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use test
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 120 |
+------------------+-----------+
1 row in set (0.00 sec)
mysql>
mysql>
mysql> flush logs;
Query OK, 0 rows affected (0.16 sec)
mysql> show binary logs;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000001 | 167 |
| mysql-bin.000002 | 120 |
+------------------+-----------+
2 rows in set (0.00 sec)
創建一個新表chenfeng并插入三條記錄:
mysql> create table chenfeng(t1 int not null primary key,t2 varchar(50),t3 datetime);
Query OK, 0 rows affected (0.13 sec)
mysql> insert into chenfeng values (1,"beijing",now());
Query OK, 1 row affected (0.02 sec)
mysql> insert into chenfeng values (2,"shanghai",now());
Query OK, 1 row affected (0.02 sec)
mysql> insert into chenfeng values (3,"zhengzhou",now());
Query OK, 1 row affected (0.03 sec)
mysql> select * from chenfeng;
+----+-----------+---------------------+
| t1 | t2 | t3 |
+----+-----------+---------------------+
| 1 | beijing | 2017-01-25 15:33:54 |
| 2 | shanghai | 2017-01-25 15:34:08 |
| 3 | zhengzhou | 2017-01-25 15:34:23 |
+----+-----------+---------------------+
3 rows in set (0.00 sec)
現在我們執行delete誤操作,刪除所有的數據:
mysql> delete from chenfeng;
Query OK, 3 rows affected (0.04 sec)
先查看binlog,生成002.sql:
mysqlbinlog mysql-bin.000002 > 002.sql
查看002.sql,并只摘取delete部分內容:
BEGIN
/*!*/;
# at 1094
#170125 15:37:10 server id 1 end_log_pos 1188 CRC32 0x53d8348f Query thread_id=197 exec_time=0 error_code=0
SET TIMESTAMP=1485329830/*!*/;
delete from chenfeng
/*!*/;
# at 1188
#170125 15:37:10 server id 1 end_log_pos 1219 CRC32 0xfe067937 Xid = 25
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
可以看到在時間2017-01-25 15:37:10我們做了delete誤操作。現在需要用mysqlbinlog恢復到這個時間點前的數據:
# mysqlbinlog mysql-bin.000002 --stop-date='2017-01-25 15:37:10' > resume.sql
執行resume.sql內容后發現數據已恢復:
mysql> select * from chenfeng;
+----+-----------+---------------------+
| t1 | t2 | t3 |
+----+-----------+---------------------+
| 1 | beijing | 2017-01-25 15:33:54 |
| 2 | shanghai | 2017-01-25 15:34:08 |
| 3 | zhengzhou | 2017-01-25 15:34:23 |
+----+-----------+---------------------+
3 rows in set (0.00 sec)
關于“怎么用mysqlbinlog做基于時間點的數據恢復”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。