假设大表表名:t_log
delete操作会记录mysql日志,大数据量的清理会耗费大量时间,所以一般得用其他方式。
1、如果大表数据对我们来说不重要,完全可以直接清理,那么可以用truncate
truncate table t_log;
truncate的操作不记录mysql日志,所以数据是不能恢复的。?
2、如果需要保留部分数据
创建表并直接保留需要的数据
create table t_log_2019 as select * from?t_log?where create_time>'2019-01-01 00:00:00';
删除数据
truncate table t_log;
恢复保留的数据
insert into t_log select * from t_log_2019;
删除临时表
drop table t_log_2019;
3、当前表数据需要全部保留,或者后续再删除
创建一个同结构的表
create table t_log_2019 like t_log;