mysql基於時間恢復的乙個過程

2021-06-19 09:26:32 字數 3967 閱讀 2224

(一)建立表

[root@sr3 ~]# /opt/mysql/bin/mysql  -h10.86.87.155 -uroot  -pinfohow

welcome to the mysql monitor.  commands end with ; or \g.

your mysql connection id is 8

server version: 5.5.16-log source distribution

oracle is a registered trademark of oracle corporation and/or its

affiliates. other names may be trademarks of their respective

owners.

type 'help;' or '\h' for help. type '\c' to clear the current input statement.

mysql> use clas

database changed

mysql> select now();

+---------------------+

| now()               |

+---------------------+

| 2013-11-26 08:14:11 |

+---------------------+

1 row in set (0.00 sec)

mysql> use clas;

database changed

mysql> create table upl (id int , user varchar(16)); 

query ok, 0 rows affected (0.16 sec)

mysql> select now();

+---------------------+

| now()               |

+---------------------+

| 2013-11-26 08:18:42 |

+---------------------+

1 row in set (0.00 sec)

(二)插入表資料

mysql> insert into upl

-> values (1,'tom'),(2,'mary'),(3,'bean');

query ok, 3 rows affected (0.07 sec)

records: 3  duplicates: 0  warnings: 0

mysql> select now();

+---------------------+

| now()               |

+---------------------+

| 2013-11-26 08:19:55 |

+---------------------+

1 row in set (0.00 sec)

(3)刪除id=2的一條資料

mysql> delete from upl where id=2;

query ok, 1 row affected (0.05 sec)

mysql>  select now();

+---------------------+

| now()               |

+---------------------+

| 2013-11-26 08:20:29 |

+---------------------+

1 row in set (0.00 sec)

(4)插入表二條資料

mysql> insert into upl values (4,'moto'),(5,'nokia');

query ok, 2 rows affected (0.03 sec)

records: 2  duplicates: 0  warnings: 0

mysql> select now();

+---------------------+

| now()               |

+---------------------+

| 2013-11-26 08:21:06 |

+---------------------+

1 row in set (0.00 sec)

(5)重新整理日誌,檢視日誌

mysql> flush logs;

query ok, 0 rows affected (0.10 sec)

mysql> show master status\g;

*************************** 1. row ***************************

file: mysqlsr3-bin.000006

position: 107

binlog_do_db:

binlog_ignore_db:

1 row in set (0.00 sec)

error:

no query specified

mysql> select now();

+---------------------+

| now()               |

+---------------------+

| 2013-11-26 08:22:29 |

+---------------------+

1 row in set (0.00 sec)

(6)刪除表

mysql> drop table up1;

error 1051 (42s02): unknown table 'up1'

mysql> drop table upl;

query ok, 0 rows affected (0.07 sec)

mysql> select now();

+---------------------+

| now()               |

+---------------------+

| 2013-11-26 08:22:57 |

+---------------------+

1 row in set (0.00 sec)

mysql>

(7)實現恢復

可以用以下語句將資料恢復到故障前

mysqlbinlog --stop-date='2013-11-26 08:14:11' /mysqldata/mysqlsr3-bin.000006 | mysql -h10.86.87.155 -u root -pinfohow

跳過故障的時間點,繼續執行後面的binlog,完成恢復

mysqlbinlog --start-date='2013-11-26 08:18:42' /mysqldata/mysqlsr3-bin.000006 | mysql  -h10.86.87.155 -u root -pinfohow

[mysql@sr3 mysqldata]$ mysqlbinlog --stop-date='2013-11-26 08:14:11' /mysqldata/mysqlsr3-bin.000006 | mysql -h10.86.87.155 -u root -pinfohow

[mysql@sr3 mysqldata]$ mysqlbinlog --start-date='2013-11-26 08:18:42' /mysqldata/mysqlsr3-bin.000006 | mysql  -h10.86.87.155 -u root -pinfohow

error 1051 (42s02) at line 23: unknown table 'upl'

[mysql@sr3 mysqldata]$

或加-s  /var/lib/myql/mysql.sock

解決方案:

Oracle恢復(七) 基於時間的恢復

首先有備份 其次知道自己想要恢復到的歷史時間 拷貝備份的所有資料檔案回來,startup mount 啟動到mount狀態 recover database until time 2012 04 10 16 43 01 穿越到今天 呵呵 因為10號發工資,所以喜歡穿越到10號 mediarecove...

MySQL 基於時間點的快速恢復方案

之所以有這樣一篇文章,是因為在前幾天的乙個晚上,要下班的時候,業務方忽然有乙個需求,是需要恢復乙個表裡面的資料,當時問了下情況,大概是這樣的 業務方不小心在乙個表裡面做了乙個update的操作,可能是where條件沒有寫對,導致表裡面的資料被寫壞了,但是資料目前還沒有落盤,只是在記憶體中的值修改了,...

基於mysql的乙個小案例分析

用root使用者登入系統,執行指令碼 建立資料庫 create database mydb61 character set utf8 選擇資料庫 use mydb61 增加 dbuser1 使用者 建立使用者 dbuser61 密碼為 dbuser61 擁有運算元據庫mydb61的所有許可權 gra...