Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  shell  >  正文 shell脚本:MySQL慢查询日志和错误日志按天轮询

shell脚本:MySQL慢查询日志和错误日志按天轮询

发布时间:2014-11-30   编辑:www.jquerycn.cn
分享一例shell脚本,实现MySQL慢查询日志和错误日志的按天轮询,有需要的朋友参考下。

为便于在出问题时排查和减小mysql日志文件大小,需对慢查询日志和错误日志按天轮询。

例子,轮询脚本(/data/scripts/mysql-log-rotate):
 

复制代码 代码示例:
"/data/dbdata/otherlog/slow_query.log" "/data/dbdata/otherlog/mysql_error.log" {
create 660 mysql mysql
dateext
notifempty
daily
maxage 60
rotate 30
missingok
compress
olddir /data/dbdata/otherlog
postrotate
if /usr/local/mysql/bin/mysqladmin ping -uroot -S /var/run/mysql/mysql.sock &>/dev/null; then
/usr/local/mysql/bin/mysqladmin flush-logs -uroot -S /var/run/mysql/mysql.sock
fi
endscript
}

crontab计划任务:
0000***(/usr/sbin/logrotate-f/data/scripts/mysql-log-rotate>/dev/null2>&1)

您可能感兴趣的文章:
shell脚本:MySQL慢查询日志和错误日志按天轮询
mysql优化之如何定位效率较低的SQL
mysql日志配置(linux与windows)
如何开启mysql和php慢日志
mysql优化之定位效率较低的SQL
mysql打开慢查询日志的方法
mysql日志使用浅析
MYSQL启用日志,查看日志,利用Mysqlbinlog工具恢复MySQL数据库
利用Mysqlbinlog工具恢复MySQL数据库的例子
logrotate对MySQL日志轮替的实例分享

[关闭]