O'Reilly logo

Managing & Using MySQL, 2nd Edition by Hugh E. Williams, Randy Yarger, George Reese, Tim King

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Log Rotation

No matter which log files you choose to enable, you need to maintain them so they do not fill up a filesystem.

Unfortunately, none of the techniques we discuss here work for the error log. Since it is written from the safe_mysqld script, it is not controlled by the MySQL server and the flush-logs command does not flush it. Also note that safe_mysqld will continue to append to it on successive restarts. You may want to modify the startup or shutdown scripts for your MySQL server to maintain the error log.

If you are running RedHat Linux, you can use mysql-log-rotate to rotate logs. It can be found in the support-files directory of your MySQL installation. It uses the logrotate utility to automatically rotate your error log for you. To install mysql-log-rotate on RedHat Linux, simply copy it to /etc/logrotate.d . You may wish to edit the script to rotate other logs that you have enabled as well. By default, it rotates only the query log. For more information on logrotate, read the manpage or refer to your RedHat documentation.

If you installed MySQL on Linux using the RPM package, mysql-log-rotate may have already been installed on your system. The RPM installer renames mysql-log-rotate to mysql when it copies it to /etc/logrotate.d. If the file /etc/logrotate.d/mysql is already there, it has already been installed.

On systems other than RedHat, you will have to devise your own scripts for rotating the logs. Depending on which logs you have enabled and how you want ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required