truncate table 恢复:
1、测试数据
mysql> select count(*) from o_order;
+----------+
| count(*) |
+----------+
| 34 |
+----------+
1 row in set (0.00 sec)
2、truncate table
mysql> truncate table o_order;
Query OK, 0 rows affected (0.05 sec)
mysql> select count(*) from o_order;
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
3、强制刷新日志
mysql> flush logs;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status;
+---------------------+----------+------------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+------------------+------------------+-------------------+
| mysql_binlog.000009 | 120 | history,realtime | mysql | |
+---------------------+----------+------------------+------------------+-------------------+
1 row in set (0.00 sec)
4.先从备份恢复:
mysql> \. his.sql
注:如无备份数据,则到逐个恢复日志
5、定位log位置
'/*!*/;
# at 1607
#141128 0:54:29 server id 1 end_log_pos 1638 CRC32 0x69cfa1df Xid = 1734
COMMIT/*!*/;
# at 1638
#141128 1:06:23 server id 1 end_log_pos 1730 CRC32 0xb0178972 Query thread_id=34 exec_time=1 error_code=0
use `history`/*!*/;
SET TIMESTAMP=1417107983/*!*/;
truncate table o_order
6、恢复数据
[root@db01 ~]# mysqlbinlog -d history --stop-position=1638 /data/mysql/mysql_binlog.000008 |mysql
7、检查数据
mysql> select count(*) from o_order;
+----------+
| count(*) |
+----------+
| 34 |
+----------+
1 row in set (0.00 sec)
1、测试数据
mysql> select count(*) from o_order;
+----------+
| count(*) |
+----------+
| 34 |
+----------+
1 row in set (0.00 sec)
2、truncate table
mysql> truncate table o_order;
Query OK, 0 rows affected (0.05 sec)
mysql> select count(*) from o_order;
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
3、强制刷新日志
mysql> flush logs;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status;
+---------------------+----------+------------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+------------------+------------------+-------------------+
| mysql_binlog.000009 | 120 | history,realtime | mysql | |
+---------------------+----------+------------------+------------------+-------------------+
1 row in set (0.00 sec)
4.先从备份恢复:
mysql> \. his.sql
注:如无备份数据,则到逐个恢复日志
5、定位log位置
'/*!*/;
# at 1607
#141128 0:54:29 server id 1 end_log_pos 1638 CRC32 0x69cfa1df Xid = 1734
COMMIT/*!*/;
# at 1638
#141128 1:06:23 server id 1 end_log_pos 1730 CRC32 0xb0178972 Query thread_id=34 exec_time=1 error_code=0
use `history`/*!*/;
SET TIMESTAMP=1417107983/*!*/;
truncate table o_order
6、恢复数据
[root@db01 ~]# mysqlbinlog -d history --stop-position=1638 /data/mysql/mysql_binlog.000008 |mysql
7、检查数据
mysql> select count(*) from o_order;
+----------+
| count(*) |
+----------+
| 34 |
+----------+
1 row in set (0.00 sec)