purge mysql自带命令清除binlog

时间:2022-09-26 04:03:18
#!/bin/bash
DATAUSER=root
DATAPASS=shiyiwen
DAY=$1 if [ ! $# == 1 ];then
echo -e "\033[32m USAGE:$0 days\033[0m"
echo -e "\033[32m Please setting days!\033[0m"
sleep 2
exit 1
fi if [[ ! "$DAY" =~ ^[1-9]{1,2}$ ]];then
echo -e "\033[31m error,please enter number\033[0m"
exit 1
fi mysql -u$DATAUSER -p$DATAPASS -e "purge master logs before date_sub(now(), interval $DAY day);"

这样会更新binlog.index里面的索引,这样有利于salve 更快的来读取index。so