MySQL實現基於時間點的恢複

來源:互聯網
上載者:User

標籤:mysql 恢複

前期說明:我每天指定了資料庫淩晨1點做全備,這天有人一不小心,刪除了某個資料庫裡面的一個表,需要恢複,怎麼弄? 


參考 :http://blog.csdn.net/zhaoyangjian724/article/details/48715321


1  確認log_bin是否開啟 

mysql> show global variables like ‘log_bin‘; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin       | ON    | +---------------+-------+ 1 row in set (0.00 sec)

 

如果沒有開啟在設定檔裡my.cnf,添加

[mysqld]

log-bin=mysql-bin

2  在test庫裡面建立一個表upl

use test;create table upl;插入資料insert into upl values (1,‘tom‘),(2,‘mary‘),(3,‘bean‘);查看資料mysql> select * from upl;+------+------+| id   | user |+------+------+|    1 | tom  ||    2 | mary ||    3 | bean

3 在時間點a備份資料庫test

mysqldump -uroot -p --databases test > /data/test.sql


4 時間點b再次登入資料庫,建立表test.t2

 mysql> create table t2 (a int); Query OK, 0 rows affected (0.00 sec) mysql> insert into t2 values(10); Query OK, 1 row affected (0.02 sec) mysql> commit; Query OK, 0 rows affected (0.00 sec) mysql> select * from t2; +------+ | a    | +------+ |   10 | +------+ 1 row in set (0.00 sec)

5 在時間點c刪除upl,t2

drop table upl;

drop table t2;


6 要求恢複到時間點b (upl和t2同時存在)

先恢複全庫  mysql -uroot -p < /data/test.sql

登入mysql發現upl表已經存在了

挖掘log-bin日誌  mysqlbinlog --start-datetime=‘2016-10-21 14:46:10‘ --stop-datetime=‘2016-10-21 14:50:35‘  mysql-bin.000001 > recovery.sql


說明:這兩個時間點只能取大概的時間,不能確定精確的時間,可以寫上面Database Backup完的那個時間,結束時間就寫刪除某個表的時間(大概) 這個mysql-bin.000001 記錄檔選擇最新的那個(距離刪除時間最近的)

然後再把這個recovery.sql倒入到資料庫裡

mysql -uroot -p < recovery.sql

再次登入mysql資料庫,發現t2也已經存在了,到此全部恢複完成!


 


本文出自 “漸行漸遠” 部落格,請務必保留此出處http://825536458.blog.51cto.com/4417836/1864945

MySQL實現基於時間點的恢複

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.