MyISAM分割槽表遷移 && 合併

longer3281發表於2016-04-27
dyn_change_yyyymm 是一張按照日期(欄位time_d)分割槽的表(myisam),只有insert,select操作。
2016年3月份起結構如下:
 CREATE TABLE `dyn_change_201603` (
  `time_d` int(8) NOT NULL COMMENT '帳期',
  `id` char(32) NOT NULL COMMENT '業務標識',
  `content` text COMMENT '內容',
  `create_time` int(11) NOT NULL COMMENT '時間',
  KEY `idx_id` (`id`),
  KEY `idx_create_time` (`create_time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='動態資料記錄表'
/*!50100 PARTITION BY RANGE (time_d)
(PARTITION dypt_20160301 VALUES LESS THAN (20160302) ENGINE = MyISAM,
 PARTITION dypt_20160302 VALUES LESS THAN (20160303) ENGINE = MyISAM,
 PARTITION dypt_20160303 VALUES LESS THAN (20160304) ENGINE = MyISAM,
 PARTITION dypt_20160304 VALUES LESS THAN (20160305) ENGINE = MyISAM,
 PARTITION dypt_20160305 VALUES LESS THAN (20160306) ENGINE = MyISAM,
 PARTITION dypt_20160306 VALUES LESS THAN (20160307) ENGINE = MyISAM,
 PARTITION dypt_20160307 VALUES LESS THAN (20160308) ENGINE = MyISAM,
 PARTITION dypt_20160308 VALUES LESS THAN (20160309) ENGINE = MyISAM,
 PARTITION dypt_20160309 VALUES LESS THAN (20160310) ENGINE = MyISAM,
 PARTITION dypt_20160310 VALUES LESS THAN (20160311) ENGINE = MyISAM,
 PARTITION dypt_20160311 VALUES LESS THAN (20160312) ENGINE = MyISAM,
 PARTITION dypt_20160312 VALUES LESS THAN (20160313) ENGINE = MyISAM,
 PARTITION dypt_20160313 VALUES LESS THAN (20160314) ENGINE = MyISAM,
 PARTITION dypt_20160314 VALUES LESS THAN (20160315) ENGINE = MyISAM,
 PARTITION dypt_20160315 VALUES LESS THAN (20160316) ENGINE = MyISAM,
 PARTITION dypt_20160316 VALUES LESS THAN (20160317) ENGINE = MyISAM,
 PARTITION dypt_20160317 VALUES LESS THAN (20160318) ENGINE = MyISAM,
 PARTITION dypt_20160318 VALUES LESS THAN (20160319) ENGINE = MyISAM,
 PARTITION dypt_20160319 VALUES LESS THAN (20160320) ENGINE = MyISAM,
 PARTITION dypt_20160320 VALUES LESS THAN (20160321) ENGINE = MyISAM,
 PARTITION dypt_20160321 VALUES LESS THAN (20160322) ENGINE = MyISAM,
 PARTITION dypt_20160322 VALUES LESS THAN (20160323) ENGINE = MyISAM,
 PARTITION dypt_20160323 VALUES LESS THAN (20160324) ENGINE = MyISAM,
 PARTITION dypt_20160324 VALUES LESS THAN (20160325) ENGINE = MyISAM,
 PARTITION dypt_20160325 VALUES LESS THAN (20160326) ENGINE = MyISAM,
 PARTITION dypt_20160326 VALUES LESS THAN (20160327) ENGINE = MyISAM,
 PARTITION dypt_20160327 VALUES LESS THAN (20160328) ENGINE = MyISAM,
 PARTITION dypt_20160328 VALUES LESS THAN (20160329) ENGINE = MyISAM,
 PARTITION dypt_20160329 VALUES LESS THAN (20160330) ENGINE = MyISAM,
 PARTITION dypt_20160330 VALUES LESS THAN (20160331) ENGINE = MyISAM,
 PARTITION dypt_20160331 VALUES LESS THAN (20160401) ENGINE = MyISAM) */

在不影響insert的情況下,需要將dyn_change_201603遷移到新環境下。
步驟如下:
1)假設當前日期為:2016年3月30日,對應分割槽dypt_20160330新環境建立dyn_change_201603表(非分割槽表)。insert 操作可以移到新環境下;
2)
將老環境下的表dyn_change_201603 重新命名為: dyn_change_201603_old;
3)到mysql的資料目錄下,將dyn_change_201603_old的資料檔案&&索引檔案scp到新環境對應的路徑下面。[注:dyn_change_201603_old此時的對應資料&&索引檔案不同與dyn_change_201603的資料&&索引檔案]
4)然後交換dyn_change_201603,dyn_change_201603_old表名。交換後,90%以上的資料都在dyn_change_201603表,而少部分資料在dyn_change_201603_old(只在分割槽dypt_20160330 中);
    dyn_change_201603接受當前insert操作

5)然後匯出dyn_change_201603_old dypt_20160330分割槽的資料(僅有少量資料),可以匯出dyn_change_201603_30.csv檔案;
6)然後將dyn_change_201603_30.csv的資料匯入dyn_change_201603;
7)alter table dyn_change_201603 analyze partition dypt_20160330。 [注:此時可在insert操作較少的時間 or 暫停insert 操作]

遷移合併完成。









來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9606353/viewspace-2089200/,如需轉載,請註明出處,否則將追究法律責任。

相關文章