-- 歸檔短信明細
CREATE TABLE IF NOT EXISTS t_mobile_send_log_his LIKE p_mobile_send_log;
rename table p_mobile_send_log to t_mobile_send_log_his_tmp;
rename table t_mobile_send_log_his to p_mobile_send_log;
insert into p_mobile_send_log (id,mobile,content,delete_flag,creat_id,creat_time,modify_id,modify_time,dahan_msg_id,tencent_data,version,type,code,ms_type,msg_text,msg_json,sms_entity_id,browser_ver,device_brand,device_model,device_type,system_level,device_ip,resolution_wh,device_imei,device_net,app_channel,app_version,app_mac,app_uuid,batch_no,biz_code,sys_code)
select id,mobile,content,delete_flag,creat_id,creat_time,modify_id,modify_time,dahan_msg_id,tencent_data,version,type,code,ms_type,msg_text,msg_json,sms_entity_id,browser_ver,device_brand,device_model,device_type,system_level,device_ip,resolution_wh,device_imei,device_net,app_channel,app_version,app_mac,app_uuid,batch_no,biz_code,sys_code from t_mobile_send_log_his_tmp order by id desc limit 0,2;
-- 後續繼續逐步增加 最大id - 2 的數據
insert into p_mobile_send_log (id,mobile,content,delete_flag,creat_id,creat_time,modify_id,modify_time,dahan_msg_id,tencent_data,version,type,code,ms_type,msg_text,msg_json,sms_entity_id,browser_ver,device_brand,device_model,device_type,system_level,device_ip,resolution_wh,device_imei,device_net,app_channel,app_version,app_mac,app_uuid,batch_no,biz_code,sys_code)
select id,mobile,content,delete_flag,creat_id,creat_time,modify_id,modify_time,dahan_msg_id,tencent_data,version,type,code,ms_type,msg_text,msg_json,sms_entity_id,browser_ver,device_brand,device_model,device_type,system_level,device_ip,resolution_wh,device_imei,device_net,app_channel,app_version,app_mac,app_uuid,batch_no,biz_code,sys_code from t_mobile_send_log_his_tmp order by id desc limit 1390002,10000;
insert into p_mobile_send_log (id,mobile,content,delete_flag,creat_id,creat_time,modify_id,modify_time,dahan_msg_id,tencent_data,version,type,code,ms_type,msg_text,msg_json,sms_entity_id,browser_ver,device_brand,device_model,device_type,system_level,device_ip,resolution_wh,device_imei,device_net,app_channel,app_version,app_mac,app_uuid,batch_no,biz_code,sys_code)
select id,mobile,content,delete_flag,creat_id,creat_time,modify_id,modify_time,dahan_msg_id,tencent_data,version,type,code,ms_type,msg_text,msg_json,sms_entity_id,browser_ver,device_brand,device_model,device_type,system_level,device_ip,resolution_wh,device_imei,device_net,app_channel,app_version,app_mac,app_uuid,batch_no,biz_code,sys_code from t_mobile_send_log_his_tmp order by id desc limit 1400002,10000;
-- 歸檔app推送明細
CREATE TABLE IF NOT EXISTS t_app_push_log_his LIKE t_app_push_log;
rename table t_app_push_log to t_app_push_log_his_tmp;
rename table t_app_push_log_his to t_app_push_log;
INSERT INTO t_app_push_log SELECT * FROM t_app_push_log_his_tmp order by id desc limit 0,2;
-- 後續逐步增加 最大id - 2 的數據
INSERT INTO t_app_push_log SELECT * FROM t_app_push_log_his_tmp where status=1 order by id desc limit 340002,10000;
INSERT INTO t_app_push_log SELECT * FROM t_app_push_log_his_tmp where status=1 order by id desc limit 350002,10000;
INSERT INTO t_app_push_log SELECT * FROM t_app_push_log_his_tmp where status=2 order by id desc limit 280002,10000;
INSERT INTO t_app_push_log SELECT * FROM t_app_push_log_his_tmp where status=2 order by id desc limit 290002,10000;
like 可以直接生成表結構 主鍵 索引 全部相同的新表 而 create table newtable as select * from oldtable where 1=2 新表僅僅只有相同的字段 不會複製主鍵 索引等等
一次insert 經測 10000條數據 還是非常快的