同步相同結構數據庫數據

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)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章