Mirror site is read only www.netnr.com
netnr/ mysql_general_log.sh 2023-09-11 11:36
MySQL 日志切割并存档
#!/bin/bash

# 日志文件路径、存档目录
log_path="/package/mysqldata"
archive_directory="/package/mysqldata/archive"

mkdir -p ${archive_directory}
# 移动日志文件到存档目录
mv ${log_path}/general.log ${archive_directory}/general_$(date +%Y%m%d_%H%M%S).log

# 连接MySQL执行FLUSH LOGS命令
mysql -uroot -pPwd123 -e "FLUSH LOGS"

# 删除历史日志文件超过30天的
find ${archive_directory} -name "general_*" -mtime +30 -exec rm {} \;