rotating mysql slow query log

前端 未结 3 2043
别跟我提以往
别跟我提以往 2021-01-15 02:47

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

3条回答
  •  萌比男神i
    2021-01-15 02:53

    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
    }
    

提交回复
热议问题