Be careful rotating MySQL logsPeter Zaitsev
If you enable logging of all queries as “slow queries” using the patch or MySQL 5.1 you can get log file to grow huge. Same may happen with general log file. In some cases we’ve got log file sizes of 100G or more which may need to be cleaned up.
Here is some danger waiting for you at least on typical Linux systems – If you follow most simple process – delete log file you do not need and run “FLUSH LOGS” so file is recreated and space reclaimed you can get into serious trouble. File close operation will when perform deletion which can be quite a long process, depending on filesystem and log file size – we’ve seen it to take 10 minutes or more in some cases. When log file is reopened MySQL will be practically unavailable causing unanticipated downtime.
The workaround for this problem is very simple – instead of deleting MySQL log file – rename it, call “FLUSH LOGS” which will be instant as it will not involve complex delete operation and when you can delete the log file you no more need.
It can be also good idea to hook up log rotate to take care of MySQL logs so you would not need to cleanup them manually. In some cases it is already setup if you use MySQL distribution supplied by OS vendor.