开发者

rotating mysql slow query log

开发者 https://www.devze.com 2023-02-02 06:18 出处:网络
My server\'s MySQL slow query log is growing day by day (37 MB now) so I want to rotate it. If I move current log file to another folder then will MySQL automatically create another log file? Think of

My server's MySQL slow query log is growing day by day (37 MB now) so I want to rotate it. If I move current log file to another folder then will MySQL automatically create another log file? Think of it like I am deleting current log file, so will MySQL automatically create a new one when anothe开发者_开发技巧r slow query comes?

Thanks


you simply cant use logrotate to do that , you will have to first change the file name in my.cnf and than do what ever wants to do.reload the mysql.

if you want the logrotate way , you will have to disable the slow query log for that time.

The logrotate thing was suggested by percona team and works for me.

/var/mysql/slow_query.log {
    nocompress
    create 660 mysql mysql
    size 1G
    dateext
    missingok
    notifempty
    sharedscripts
    postrotate
       /usr/local/bin/mysql -e 'select @@global.long_query_time into @lqt_save; set global long_query_time=2000; select sleep(2); FLUSH LOGS; select sleep(2); set global long_query_time=@lqt_save;'
    endscript
    rotate 150
}


You can use logrotate script to periodically rotate MySQL logs, and possibly keep a limited number of previous logs (to save space). You can configure it with any schedule you like.

Personally, I found it easy to configure using Webmin GUI


You can setup a daily cron which will be ziping and emptying the logfile:

zip /tmp/$(date +%Y-%m-%d)-slow-query-log.zip /var/lib/mysql/slow-queries.log
cat /dev/null > /var/lib/mysql/slow-queries.log

Of course, if your slow query log has so much content logged every day you (or someone else) ought to investigate and fix the bad queries :)

0

精彩评论

暂无评论...
验证码 换一张
取 消