日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
MySQL大表備份的簡單方法

MySQL大表備份是一個我們常見的問題,下面就為您介紹一個MySQL大表備份的簡單方法,希望對您學習MySQL大表備份方面能有所幫助。

成都創(chuàng)新互聯(lián)主要從事做網(wǎng)站、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)宜秀,10年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108

這里所說的大表是超過4G以上的表,我目前見到過***為60多G的單表,對于這種表每天一個全備可以說是一件很痛苦的事。
那么有沒有辦法,可以實現(xiàn)一個全備加增量的備份呢。
答案當然是有的。

在常規(guī)環(huán)境直可以用全備加binlog一同保存。
這種環(huán)境大多可以用一個Slave上進行備份操作。

思路:
先停止Slave的同步,刷新buffer,對于Innodb 如果想直接拷貝還需要把innodb_max_dirty_pages_pct這個值置為零,然后在執(zhí)行一次flush tables;
就可以cp了。如果是Dump出來可以這這樣做。

這個方案目前來看也是比較***的,但一個并發(fā)力度大的應(yīng)用一天的Binlog有可能能達到50G-60G,這樣的系統(tǒng)開Binlog可以說是對系統(tǒng)的IO性能及整體性能都有早影響。

另一種方案就是基于表的上數(shù)據(jù)的羅輯變化進行備份。
主體思想:全備加邏輯備份。
邏輯備份:當有數(shù)據(jù)插入時,利用觸發(fā)器同時寫入另一個表,當數(shù)據(jù)更新時,我們同時記錄一下,更新后的數(shù)據(jù)情況到另一個表。
當有刪除操作時,只需要記錄一下,刪除的主建ID就行。

例子:
要備份的表:

 
 
 
  1. CREATE TABLE `wubx` (  `id` int(11) NOT NULL auto_increment,   
  2. `user_id` int(11) NOT NULL default '0',   
  3. `friend_id` int(11) NOT NULL default '0',   
  4. `dir_id` int(11) NOT NULL default '0',   
  5. `created` int(11) NOT NULL default '0',   
  6. UNIQUE KEY `id` (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;  

對于這個表我們需要建一個記錄有新數(shù)據(jù)變化的表為:

 
 
 
  1. mysql> create table wubx_ii like wubx;  
  2. Query OK, 0 rows affected (0.00 sec)  
  3.  
  4. mysql> create table wubx_uu like wubx;  
  5. Query OK, 0 rows affected (0.00 sec)  
  6. mysql> create table wubx_dd ( id int(11));  
  7. Query OK, 0 rows affected (0.00 sec)  
  8.  

建立相應(yīng)的觸發(fā)程器

 
 
 
  1. 記錄insert的操作:  
  2. delimiter //  
  3. create trigger wubx_ii after insert on wubx for each row begin insert into wubx_ii set id=new.id,user_id=new.user_id,friend_id=new.friend_id,dir_id=new.dir_id,created=new.created; end//  
  4. 記錄update的操作:  
  5. create trigger wubx_uu after update on wubx for each row begin replace into wubx_uu set id=new.id,user_id=new.user_id,friend_id=new.friend_id,dir_id=new.dir_id,created=new.created; end//  
  6. 記錄刪除的操作:  
  7. create trigger wubx_dd after delete on wubx for each row begin insert into wubx_dd values(old.id); end//  
  8.  
  9. delimiter ;  
  10.  

操作:
先備份原始表wubx里的數(shù)據(jù):
進行:

 
 
 
  1. insert into wubx values(”,1,10,1,1198464252);  
  2. insert into wubx values(”,1,11,1,1198464252);  
  3. insert into wubx values(”,1,2,1,1198464252);  
  4. insert into wubx values(”,2,10,1,1198464252);  
  5. insert into wubx values(”,2,12,1,1198464252);  
  6. insert into wubx values(”,3,12,1,1198464252);  
  7. update wubx set dir_id=5 where user_id=3;  
  8. update wubx set dir_id=4 where user_id=3;  
  9. delete from wubx where user_id=2 and friend_id=12;  

現(xiàn)在要實現(xiàn)增量備份:
取出insert的操作:

 
 
 
  1. mysql -e ” select concat(‘replace into wubx set id=’,id,’,user_id=’,user_id,’,friend_id=’,friend_id,’,dir_id=’,dir_id,’,created=’,created,’;') from wubx_ii;”>>backup_ii.sql  

取出update的操作:

 
 
 
  1. mysql -e ” select concat(‘update wubx set user_id=’,user_id,’,friend_id=’,friend_id,’,dir_id=’,dir_id,’,created=’,created,’ where id=’,id,’;') from wubx_uu;”>>backup_uu.sql  

取出delete的操作:

 
 
 
  1. mysql -e “select concat(‘delete from wubx where id=’,id,’;') from wubx_dd”>>backup_dd.sql  

這樣利用這些邏輯的備份加是完畢備份恢復(fù)到當前恢復(fù)點就很容易了。這里不演示。

這個操作***用一個程序完成,當取完羅輯備份后,做一個標記點去清楚備份完的數(shù)據(jù),以保證,邏輯記錄表里的數(shù)據(jù)量比較少是正確的。

【編輯推薦】

MySQL分表處理的實現(xiàn)方法

MySQL授權(quán)表使用示例

MySQL多表刪除的實現(xiàn)

MySQL獨立表空間的優(yōu)缺點

MySQL MyISAM表結(jié)構(gòu)的恢復(fù)


分享標題:MySQL大表備份的簡單方法
本文URL:http://www.dlmjj.cn/article/djejgcc.html