_log_pos 663373 CRC32 0x17a48bfc? ? Table_map: `hellodb`.`students` mapped to number 152
# at 663373
#170116 15:22:59 server id 106? end_log_pos 663424 CRC32 0x0acbd405? ? Write_rows: table id 152 flags: STMT_END_F
### INSERT INTO `hellodb`.`students`
### SET
###? @1=100 /* INT meta=0 nullable=0 is_null=0 */
###? @2='www' /* VARSTRING(150) meta=150 nullable=0 is_null=0 */
###? @3=100 /* TINYINT meta=0 nullable=0 is_null=0 */
###? @4=1 /* ENUM(1 byte) meta=63233 nullable=0 is_null=0 */
###? @5=3 /* TINYINT meta=0 nullable=1 is_null=0 */
###? @6=5 /* INT meta=0 nullable=1 is_null=0 */
# at 663424
#170116 15:22:59 server id 106? end_log_pos 663455 CRC32 0x1f37c970? ? Xid = 1139
COMMIT/*!*/;
?
step5 准备恢复的数据
?
mysqlbinlog mysql.000010 --stop-position=662771 > /root/22.sql? ? ? ? ? ? ? ? ? ? ? ? ? ? # 导出step2中第一个DELETE前的数据
mysqlbinlog mysql.000010 --start-position=662904? --stop-position=663027 > /root/33.sql? # 导出step2中这个正常的grant授权操作语句
mysqlbinlog mysql.000010 --start-position=663310? > /root/44.sql? ? ? ? ? ? ? ? ? ? ? ? ? # 导出step2中的那个正常的INSERT操作及其后面的全部SQL操作
?
step6 开始恢复数据
?
/etc/init.d/mysql start
mysql < /root/all.sql
mysql < /root/22.sql
mysql < /root/33.sql
mysql < /root/44.sql
?
step7 检查恢复后结果
?
> use hellodb;
> SELECT * from students where `StuID`=100 AND `Name`='www';
+---------+--------+-------+----------+-----------+-------------+
|? StuID | Name? |? Age | Gender? |? ClassID |? TeacherID |
|---------+--------+-------+----------+-----------+-------------|
|? ? 100 | www? ? |? 100 | F? ? ? ? |? ? ? ? 3 |? ? ? ? ? 5 |
+---------+--------+-------+----------+-----------+-------------+
> SELECT * from scores where `StuID`=8 AND `ID`=14;
+------+---------+------------+---------+
|? ID |? StuID |? CourseID |? Score |
|------+---------+------------+---------|
|? 14 |? ? ? 8 |? ? ? ? ? 4 |? ? ? 57 |
+------+---------+------------+---------+
> SELECT * from scores where `StuID`=5 AND `ID`=10;
+------+---------+------------+---------+
|? ID |? StuID |? CourseID |? Score |
|------+---------+------------+---------|
|? 10 |? ? ? 5 |? ? ? ? ? 7 |? ? ? 63 |
+------+---------+------------+---------+
?
可以看到恢复的效果不错。