mysql删除某张表的数据,只保留最近五天的数据

#! /bin/bash
mysql -u -p DataMonitor -e "delete from mongo_oper where upd_time<date_add(now(),interval -5 day)"
if [ $? -eq 0 ]
then
echo "delete data from DataMonitor.mongo_oper 5 days ago ok..."
else
date
echo "delete data from DataMonitor.mongo_oper 5 days ago failed, please check..."

fi


并将脚本放到crontab执行计划中,每天自动执行。

展开阅读全文

没有更多推荐了,返回首页