下面小編就為大家帶來一篇mysql 找回誤刪表的資料方法(必看)。小編覺得蠻不錯的,現在就分享給大家,也給大家做個參考。一起跟著小編過來看看吧。
有備份的話很簡單,只需要產生一個最近備份的數據,然後用mysqlbinlog找回備份時間點之後的數據,再恢復即可。
如果沒有備份可能就會比較麻煩,找回資料的成本也是非常之高的.
下面介紹下mysqlbinlog找回備份時間點之後的數據的方法:
做個簡單的實驗,將mysql的表格資料刪除之後,然後用mysqlbinlog,找回剛才刪除的表格的資料。
app表的建立時間和資料的插入
原理: mysqlbinlog
前提: mysql開啟了bin log日誌
#測試刪除之前:
mysql> show tables;
+-----------------------+
| Tables_in_report_sina |
+-----------------------+
| app |
| test |
+-----------------------+
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2013-02-04 11:45:44 |
+---------------------+
1 row in set (0.01 sec)
mysql> select count(1) from app;
+----------+
| count(1) |
+----------+
| 10 |
+----------+
1 row in set (0.01 sec)
##
mysql> delete from app where id =1; Query OK, 1 row affected (0.00 sec) mysql> mysql> delete from app where id <6; Query OK, 4 rows affected (0.01 sec) mysql> select count(1) from app; +----------+ | count(1) | +----------+ | 5 | +----------+ 1 row in set (0.00 sec) mysql> select now(); +---------------------+ | now() | +---------------------+ | 2013-02-04 12:08:45 | +---------------------+
開始找回數據:1.找到bin log的位置:
/app/mysql/log -rw-rw---- 1 mysql mysql 17K Feb 4 11:43 alert.log -rw-rw---- 1 mysql mysql 1.0K Nov 1 14:52 master-bin.000001 -rw-rw---- 1 mysql mysql 126 Dec 25 14:00 master-bin.000002 -rw-rw---- 1 mysql mysql 126 Dec 25 14:02 master-bin.000003 -rw-rw---- 1 mysql mysql 126 Dec 25 14:02 master-bin.000004 -rw-rw---- 1 mysql mysql 107 Dec 25 14:02 master-bin.000005 -rw-rw---- 1 mysql mysql 13K Feb 4 12:02 master-bin.000006
mysqlbinlog --start-date='2013-02-04 10:00:00' --stop-date='2013-02-04 12:08:45' /app/mysql/log/master-bin.000006 >/app/mysql/mysql_restore_20130204.sql
create database for_bak;
匯出目前資料庫中被誤刪的表app
mysqldump -uroot -ppwd my_db app > /app/mysql/app.sql
mysql -root -ppwd for_bak < /app/mysql/app.sql
SET TIMESTAMP=1359949544/*!*/; BEGIN /*!*/; # at 12878 #130204 11:45:44 server id 1 end_log_pos 12975 Query thread_id=5 exec_time=974 error_code=0 SET TIMESTAMP=1359949544/*!*/; delete from app where id =1 /*!*/; # at 12975 #130204 11:45:44 server id 1 end_log_pos 13002 Xid = 106 COMMIT/*!*/; # at 13002 #130204 11:45:44 server id 1 end_log_pos 13077 Query thread_id=5 exec_time=1013 error_code=0 SET TIMESTAMP=1359949544/*!*/; BEGIN /*!*/; # at 13077 #130204 11:45:44 server id 1 end_log_pos 13175 Query thread_id=5 exec_time=1013 error_code=0 SET TIMESTAMP=1359949544/*!*/; delete from app where id <6 /*!*/; # at 13175 #130204 11:45:44 server id 1 end_log_pos 13202 Xid = 107 COMMIT/*!*/; DELIMITER ; # End of log file
以上是mysql怎麼恢復刪除的表? mysql找回誤刪表的資料方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!