小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

mysqldump mysqlbinlog恢復(fù)測試 | 惜分飛

 面包小屋 2013-12-11

mysqldump+mysqlbinlog恢復(fù)測試

鏈接:http://www./1232.html

標(biāo)題:mysqldump+mysqlbinlog恢復(fù)測試

作者:惜分飛?版權(quán)所有[文章允許轉(zhuǎn)載,但必須以鏈接方式注明源地址,否則追究法律責(zé)任.]

一、模擬環(huán)境
mysql> create database test;
Query OK, 1 row affected (0.02 sec)

mysql> use test;
Database changed
mysql> reset master;
Query OK, 0 rows affected (0.04 sec)

mysql> show binary logs;
+—————–+———–+
| Log_name | File_size |
+—————–+———–+
| mysqlbin.000001 | 107 |
+—————–+———–+
1 row in set (0.00 sec)

mysql> create table t(id int,name varchar(10));
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t values(1,’aaaa’);
Query OK, 1 row affected (0.01 sec)

mysql> insert into t values(2,’bbbb’);
Query OK, 1 row affected (0.00 sec)

二、使用mysqldump備份數(shù)據(jù)
mysqldump -u root -ppassw0rd –skip-opt –extended-insert=false –master-data=2 –single-transaction –allow-keywords –add-locks –add-drop-table -F -q test >/tmp/test.sql

三、繼續(xù)操作
mysql> insert into t values(3,’cccc’);
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…
Connection id: 208
Current database: test

Query OK, 1 row affected (0.00 sec)

mysql> insert into t values(4,’dddd’);
Query OK, 1 row affected (0.00 sec)

mysql> drop table t;
Query OK, 0 rows affected (0.04 sec)

mysql> create table t1 as
-> select * from information_schema.tables;
Query OK, 79 rows affected (0.27 sec)
Records: 79 Duplicates: 0 Warnings: 0

四、報(bào)告誤刪除表,開始恢復(fù)準(zhǔn)備
mysql> show binary logs;
+—————–+———–+
| Log_name | File_size |
+—————–+———–+
| mysqlbin.000001 | 605 |
| mysqlbin.000002 | 14686 |
+—————–+———–+
2 rows in set (0.00 sec)

tee /tmp/output.txt
Logging to file ‘/tmp/output.txt’
mysql> show binlog events in ‘mysqlbin.000002′;
……………………省略
mysql> notee
Outfile disabled.
mysql> exit
Bye

查找刪除表的位置(起點(diǎn)和終點(diǎn))
[root@ECP-UC-DB1 tmp]# cat output.txt |grep “DROP TABLE”
| mysqlbin.000002 | 461 | Query | 1 | 564 | use `test`; DROP TABLE `t` /* generated by server */
[root@ECP-UC-DB1 mysqllog]# cat /tmp/test.sql |grep MASTER
– CHANGE MASTER TO MASTER_LOG_FILE=’mysqlbin.000002′, MASTER_LOG_POS=107;

生成恢復(fù)sql語句
mysqlbinlog –start-position=107 –stop-position=461 mysqlbin.000002>/tmp/drop.sql
mysqlbinlog –start-position=564 mysqlbin.000002>>/tmp/drop.sql

五、開始恢復(fù)
找一個(gè)測試庫,拷貝/tmp/drop.sql和/tmp/test.sql到備庫,然后進(jìn)行恢復(fù)
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> use test;
Database changed
mysql> source /tmp/test.sql
mysql> source /tmp/drop.sql

六、測試恢復(fù)結(jié)果
mysql> show tables;
+—————-+
| Tables_in_test |
+—————-+
| t |
| t1 |
+—————-+
2 rows in set (0.00 sec)

mysql> select * from t;
+——+——+
| id | name |
+——+——+
| 1 | aaaa |
| 2 | bbbb |
| 3 | cccc |
| 4 | dddd |
+——+——+
4 rows in set (0.00 sec)

mysql> select count(*) from t1;
+———-+
| count(*) |
+———-+
| 79 |
+———-+
1 row in set (0.02 sec)

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多