Rotating Mysql Slow Query Log

Saturday, May 28, 2016

How To Rotating Mysql Slow Query Log :-


as assumptions.
1. Your mysql user is “mysql”
2. Your mysql slow query log is /var/log/mysql/mysql-slow.log

The script is written to perform the following actions:
1. Rotate weekly
2. Retain 3 rotations (3 files + live log)
3. Compress on rotate (gzip)
4. Create new logfile with 660 permissions chowned to mysql:mysql
5. Run: mysqladmin flush-logs

Note- Please be aware that the flush logs command will also rotate any binary logging currently in place, Note:- please ensure this will not adversely affect your deployment prior to use
Note:- Please ensure you carry out your own testing prior to deploying this script into a live environment.

#
# place this script in /etc/logrotate.d/ or your appropriate logrotate dir.
#
# NOTE: if you are reliant on binlogs i.e. for replication, 'flush logs' closes the current binlog and moves to the next itteration of log files
# You should test this does not cause an issue with your deployment before using this script

/var/log/mysql/mysql-slow.log {
    weekly
    rotate 3
    compress
    missingok
    notifempty
    sharedscripts
    create 660 mysql mysql
    postrotate
        /usr/bin/mysqladmin flush-logs
    endscript
}

0 comments:

About This Blog

Lorem Ipsum

  © Copyright 2009 Linux-HelpLine.Blogspot.com

Back to TOP