每隔1000s删除依次mysql中大表数据

zabbix的history_uint表的一天的数据就高达3000w,总共有6个月的数据。若要从history_uint中取数据的时候使得整个zabbix都很深重。所以需要清理history_uint表无用数据。直接使用delete指定时间删除需要删除的数据过多导致执行sql语句不明显。
想到从起始时间每增加1000s删除指定时间内数据

#!/usr/bin/bash
#-*- coding:utf-8 -*-

n=1000
endtime=1531584022

while (( ${endtime} <= 1539532800 ))
do
    starttime=$(mysql -hlocalhost -uroot -ppassword -N -e "SELECT clock FROM zabbix.history_uint limit 1;")
    let endtime=${starttime}+${n}
    mysql -hlocalhost -uroot -ppassword -N -e  "delete from zabbix.history_uint where clock >= ${starttime} and clock <= ${endtime}"
done
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容