美文网首页
每隔1000s删除依次mysql中大表数据

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

作者: 小王同学123321 | 来源:发表于2019-01-03 22:04 被阅读0次

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

相关文章

网友评论

      本文标题:每隔1000s删除依次mysql中大表数据

      本文链接:https://www.haomeiwen.com/subject/zufcrqtx.html