Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

logrotate でmysqlのquery.logを小さく保つ

More than 5 years have passed since last update.

開発環境で、全queryをログ出力していた場合、気がついたら数百MBになっていることがあるので対応。

参考

設定

/etc/logrotate.d/mysql
/var/log/mysql/query.log {
    minsize 10M
    rotate 0
    missingok
    create 0666 mysql mysql
    postrotate
        /opt/mysql/bin/mysqladmin flush-logs
    endscript
}
  • これで深夜に /var/log/mysql/query.log が10Mを超えていたらローテーションしてくれる。

動作確認

dry-run
logrotate -d /etc/logrotate.d/mysql
即時実行
logrotate -f /etc/logrotate.d/mysql

ログ

cat /var/lib/logrotate.status
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away