MySQL的增量備份與恢複

來源:互聯網
上載者:User

標籤:delete   lis   creat   .com   技術   sql   tar   備份資料庫   val   

MySQL增量備份與恢複
  • 增量備份:只備份那些在上次完全備份或者增量備份後被修改的檔案才會被備份。

  • 優點:沒有重複資料,備份量不大,時間短。

  • 缺點:需要上一次完全備份及完全備份之後所有的增量備份才能恢複,而且對所有增量備份進行逐個反推恢複,操作較為繁瑣。
一、增量備份1、編輯MySQL設定檔,開啟二進位功能

vim /etc/my.cnf

 log-bin=mysql-bing        #添加二進位記錄檔

systemctl restart mysql.service

  • 服務重啟之後會在/use/local/mysql/data目錄下產生一個空的二進位記錄檔;

2、建立以基本資料庫

mysql -u root -p #進入MySQL

create database client; #建立一個名為client的庫

use client; #使用資料庫

create table info (name varchar(10),score decimal(5.2)); #建立表

insert into info (name,score) values (‘zhangsan‘,88); #插入內容

insert into info (name,score) values (‘lisi‘,88);

quit #退出MySQL

3、備份資料庫,並產生新的二進位記錄檔;

mysqldump -u root -p client test > /opt/client.sql

mysqladmin -u root -p flush-logs

  • 資料庫中的內容會產生到第一個二進位記錄檔中,除此之外還會產生一個空的二進位記錄檔;

4、在資料庫中添加新的內容,並產生新的二進位記錄檔;

mysql -u root -p

use client

insert into info (name,score) values (‘test01‘,88);

quit #退出MySQL

mysqladmin -u root -p flush-logs

  • 資料庫中新添加的內容會產生到第二個二進位記錄檔,同時產生一個空的二進位記錄檔;

二、恢複1、刪除表,並進行完全備份恢複操作;

mysql -u root -p ;

use client;

drop tables test;

quit;

mysql -u root -p client < /opt/client.sql

2、使用二進位記錄檔進行恢複操作;

mysqlbinlog --no-defaults /usr/local/mysql/data/mysql-bin.000002 | mysql -u root -p

三、基於時間點與位置的恢複1、插入兩條資料內容,並刪除一條資料,類比操作失誤;

mysql -u root -p

use client

insert into info (name,score) values (‘test01‘,88);

delete from test where name=‘lisi‘;

insert into info (name,score) values (‘test02‘,88);

quit

2、產生二進位記錄檔,刪除表,並進行完全備份恢複操作;

mysqladmin -u root -p flush-logs

mysql -u root -p ;

use client;

drop tables test;

quit

mysql -u root -p client < /opt/client.sql

3、按時間點進行恢複(跳過誤操作時間);

mysqlbinlog --no-defaults --stop-datetime=‘18-07-06 10:39:23‘ /usr/local/mysql/data/mysql-bin.000003 | mysql -u root -p

mysqlbinlog --no-defaults--start-datetime=‘18-07-06 10:39:33‘ /usr/local/mysql/data/mysql-bin.000003 | mysql -u root -p

4、按位置進行恢複(跳過錯誤的位置);

mysqlbinlog --no-defaults --stop-position=‘1151‘ /usr/local/mysql/data/mysql-bin.000003 | mysql -u root -p

mysqlbinlog --no-defaults--start-position=‘1226‘ /usr/local/mysql/data/mysql-bin.000003 | mysql -u root -p

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.