可以搞个存储过程:
create table history_tmp like history;
maxid=select max(id) from history;
minid=select id from history where addtime>"2013-01-01 00:00" order by addtime asc limit 1;
last=0;
set autocommit=1;
for(i=minid;i=last and id=last and id<=maxid;
alter table history rename to history_2012;
alter table history_tmp rename to history;
unlock tables;
commit;
缺点:
- insert into history_tmp select * from history where id>=last and id<=maxid; 可能会超时吗?
- insert into history_tmp select * from history where id>=last and id<=maxid; 如果不是按Pk 索引,是一些过期的券的dealine 时间,效率如何?
面对上面的手工触发器,安全性很低。 下面推荐这款工具:
- Percona pt-archiver重构版--大表数据归档工具 希望能帮到你节省磁盘成本。
- Mydumper