清除n天以前的日志文件以及mysql-bin文件
web_def_host="1.2.3.4" #mysql的ip web_def_port=3306 #mysql的端口 web_def_username="tester" #mysql的用户 web_def_password="123" #mysql的密码 web_def_mysql_expire_logs_days=7 #删除7天以前的mysql-bin,但是最后至少保留一个文件 mysql_exe="mysql -h $web_def_host -P $web_def_port -u $web_def_username --password=$web_def_password -e " if [ "$web_def_mysql_expire_logs_days" -gt 0 ] then #获取n天以前被修改的mysql-bin文件, logFileName=`find $web_def_mysql_data_path -follow -atime -$web_def_mysql_expire_logs_days -name 'mysql-bin.0*' |sort|head -1` if [ "$logFileName" != "" ] then logFileName=`basename $logFileName` echo $mysql_exe "\"PURGE MASTER LOGS TO '$logFileName'\"" $mysql_exe "PURGE MASTER LOGS TO '$logFileName'"; fi fi