[Level 2] Rotate MySQL General Log and Slow Query Log.

By default, general Log and slow query log will not be rotated in MySQL Server. So, we can use "logrotate" on Linux.
All we have to do is to create a file named /etc/logrotate.d/mysqld,
and the setting as following:



/var/lib/mysql/mysqld-slow.log /var/lib/mysql/mysqld.log {
    weekly
    rotate 8
    create 0644 mysql mysql
    missingok
    notifempty
    sharedscripts
    postrotate
    # flush-logs and the MySQL account granted with RELOAD permission
    /usr/bin/mysqladmin -uroot -padmin123 flush-logs
    endscript
}


The way to test:

# logrotate -fv /etc/logrotate.d/mysqld


Wish this helps.

regards,
Stanley Huang

Comments

Popular posts from this blog

[Level 2] Shell Interactive With Zenity Episode 5 -- list

[Level 2] iif in Python