MyISAM分区表迁移 && 合并

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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9606353/viewspace-2089200/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值