需求:mysql有表需要清理1个月以前的数据
执行方案(晚上):不要锁表
1.新建一个表,两个表结构一样
2.把不删除的内容转移到新表,即把一个月内的数据转移到新表
3.检查新表内容,确认数据迁移无误
4.删除旧表,新表rename
操作:表名:t_sceneauto_log
1、新建表
create table t_sceneauto_log_new like t_sceneauto_log;
2、将所需数据迁移到新表
insert into t_sceneauto_log_new select * from t_sceneauto_log WHERE log_time > DATE_ADD(CURDATE(),INTERVAL -1 MONTH);
3、检查评估新表
4、将旧表备份
rename table t_sceneauto_log to t_sceneauto_log_bak;
5、重命名新表
rename table t_sceneauto_log_new to t_sceneauto_log;
6、观察一段时间,新表运行正常后,删除旧表
drop table t_sceneauto_log_bak;