#!/bin/bash OK="2019-05-31" tmp="" dt=`date -d "-${i} day" '+%Y-%m-%d %H:%M:%S'` for i in {793..168} do dt=`date -d "-${i} day" '+%Y-%m-%d %H:%M:%S'` tmp=${dt:0:10} echo $tmp if [ ${tmp} == ${OK} ];then exit 0 fi dt=\'${dt}\' echo ${dt} #mysql -hXXX table_name -P3306 -e "select count(*) from event where id < ${dt};" mysql -hXXX table_name -P3306 -e "delete from event where id < ${dt};" sleep 5 done
# 这里一天一天地删除数据,但是需要注意,这里是根据date命令推算出来需要删除数据的时间段,需要根据自己的具体情况而定循环的开始与结束时间