#!/bin/bash
# water QQ:5846690
MYSQL="/www/servers/mysql"
MYSQL_BIN=$MYSQL/bin/mysql
MYSQL_DATA=$MYSQL/var
USER="root"
PASS="password"
CFL="/tmp/mm.log"
function SAVE_CF {
$MYSQL_BIN -u$USER -p"$PASS" -e "show master status\G" | grep "File:" | awk -F": " '{print $2}' > $CFL
echo "save cf sucess"
}
if [[ -f $CFL ]];then
CF=`cat $CFL`
if [[ -f $MYSQL_DATA/$CF ]];then
$MYSQL_BIN -u$USER -p"$PASS" -e "PURGE MASTER LOGS TO '$CF';"
echo "del log sucess"
fi
SAVE_CF
else
SAVE_CF
fi
加入cron,每周执行一次
05 3 * * 1 root /bin/mysql_log_clear.sh