注:MySQLdump備份數(shù)據(jù)庫實(shí)驗(yàn)(本文有兩種方法實(shí)現(xiàn)備份,本實(shí)驗(yàn)使用的法1)
站在用戶的角度思考問題,與客戶深入溝通,找到鹽都網(wǎng)站設(shè)計(jì)與鹽都網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋鹽都地區(qū)。
步驟:
1.用mysqldump對數(shù)據(jù)庫完全備份
法1:
# mysqldump --all-databases --lock-all-tables --master-data=2 --flush-logs > /backup/all-`date +%F`.sql
鎖定表后滾動binlog數(shù)據(jù)文件,然后再備份數(shù)據(jù)庫,下次增量備份時只需要從新創(chuàng)建的binlog文件開始即可
或者:
法2:
# mysqldump --all-databases --lock-all-tables --master-data=2 > /backup/all-`date +%F`.sql
并打開備份的文件,查看這一行:
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000010', MASTER_LOG_POS=8230;
找到MASTER_LOG_POS=8230;代表著備份的結(jié)束事務(wù)點(diǎn)為8230,則增量備份需要從8230開始記錄備份;
2.嘗試著修改數(shù)據(jù)庫中的數(shù)據(jù),新建text2表,并插入一行數(shù)據(jù)(模擬線上運(yùn)行新增數(shù)據(jù))
MariaDB [hellodb]> create table test2(id int);
Query OK, 0 rows affected (0.09 sec)
MariaDB [hellodb]> insert into test2 values (1);
Query OK, 1 row affected (0.04 sec)
3.使用mysqlbinlog命令做增量備份
法1:
# mysqlbinlog mysql-bin.000011 > /backup/zlbf-`date +%F`.sql
或者:
法2:
# mysqlbinlog --start-position=8230 mysql-bin.000010 > /backup/zlbf-`date +%F`.sql
4.再次嘗試著修改數(shù)據(jù)庫中的數(shù)據(jù):刪除text1表(作為未來得及備份的數(shù)據(jù))
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| test2 |
| text1 |
| toc |
+-------------------+
9 rows in set (0.00 sec)
MariaDB [hellodb]> drop table text1;
Query OK, 0 rows affected (0.17 sec)
5.刪除hellodb數(shù)據(jù)庫,測試數(shù)據(jù)恢復(fù)
MariaDB [hellodb]> drop database hellodb;
Query OK, 8 rows affected (0.07 sec)
6.導(dǎo)出,未來得及備份的binlog文件
# mysqlbinlog mysql-bin.000011 > /backup/binlog.`date +%F`.sql
并修改導(dǎo)出的binlog文件,刪除掉末尾導(dǎo)致數(shù)據(jù)庫刪除的sql語句
#vim binlog.2015-04-09.sql
# at 355
#150409 0:15:01 server id 1 end_log_pos 442 Query thread_id=6104 exec_time=0 error_code=0
SET TIMESTAMP=1428509701/*!*/;
drop database hellodb (刪除此行的誤操作sql語句)
/*!*/;
DELIMITER ;
# End of log file
7.開始還原
首先還原完全備份:
# mysql < all-2015-04-08.sql
查看還原的數(shù)據(jù):(可以看見完全備份的數(shù)據(jù)已然恢復(fù)回來)
MariaDB [(none)]> use hellodb;
Database changed
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| text1 |
| toc |
+-------------------+
8 rows in set (0.02 sec)
接著還原增量備份:
# mysql < zlbf-2015-04-09.sql
查看還原的數(shù)據(jù):(可以看到增量備份以前的數(shù)據(jù)也已經(jīng)恢復(fù))
MariaDB [(none)]> use hellodb;
Database changed
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| test2 |
| text1 |
| toc |
+-------------------+
9 rows in set (0.03 sec)
接著通過binlog文件恢復(fù)未備份的數(shù)據(jù):
# mysql < binlog.2015-04-09.sql
查看還原的數(shù)據(jù):(未備份時候刪除的text1表也已經(jīng)成功刪除,可以看到未備份的數(shù)據(jù)也成功恢復(fù))
MariaDB [(none)]> use hellodb;
Database changed
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes |
| coc |
| courses |
| scores |
| students |
| teachers |
| test2 |
| toc |
+-------------------+
8 rows in set (0.00 sec)
至此備份恢復(fù)實(shí)驗(yàn)完成;
本文名稱:mysqldump&binlog做完全備份
當(dāng)前網(wǎng)址:http://chinadenli.net/article22/gsgecc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、域名注冊、做網(wǎng)站、網(wǎng)站導(dǎo)航、靜態(tài)網(wǎng)站、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)