Can you use the binary logs to undo a DELETE? Maybe, if you're using ROW format logging. The difference between a delete and an insert event could be just one byte - the one that maps it as a DELETE_ROWS_EVENT or a WRITE_ROWS_EVENT. Let's try it.
I've already populated this table with a few rows:
CREATE TABLE `undo_test` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`t` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP,
`v` varchar(20) DEFAULT NULL,
`b` blob,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
Save a hash so we can see if the undo really works later:
mysql -e "SELECT * FROM test.undo_test" | md5sum >
before.md5
Delete an unwanted row:
DELETE FROM undo_test;
Query OK, 1693 rows affected (0.14 sec)
Oops! Forgot the WHERE clause! And of course I don't have any recent …
[Read more]