shell定时清理mysql记录

shell定时清理mysql记录

摘要

shell定时清理mysql记录

每天10点调度

crontab -e

0 10 * * * (cd /data/bin/shell ;sh clean_log.sh > ./clean_log.log 2>&1 )

脚本内容

/data/bin/shell/clean_log.sh

DT=`date -d '-185 days' +'%Y-%m-%d %H:%M:%S'`
username='db_user'
password='dbpwd'
db_ip='127.0.0.1'
port='3306'
db_name='dbName'

MYSQL="/usr/bin/mysql -u${username} -p${password} -h ${db_ip} -P${port} ${db_name} "

$MYSQL -e "delete from user_log where createtime < '${DT}' ;"
echo $DT