Is there a simple and straightforeword way to limit mysql's general query log to a certain size? Keeping the log quickly gets out of hand, it grows by nearly 10mb per minute. I only need the recent 30 minutes or so though. Is there a way to just limit it to about 300mb and then just have it delete from the beginning of the file as it continues to write at the end.

I do not need a complex log rotation scheme set up and I -DO- need the log to contain a "rolling window" of the most recent 30 minutes. Any logs older than 30 minutes are _absolutely worthless_ for what I need them for and a file that has only the most recent 15 minutes (and having to look in another file for the previous 15) is very inconvenient.


8 Years
Discussion Span
Last Post by rch1231

For FreeBSD to rotate the Slow or General Query log the following can be added to /etc/newsyslog.conf:

# rotates the mysql logs when they reach 1 meg
# and keeps 7 copies
/var/db/mysql/file-name.log mysql:mysql 600 7 1000 * J
/var/db/mysql/file-name.err mysql:mysql 600 7 1000 * J

Alternatively from version 5.1.12 the log can stopped and started from mysql admin without stopping the server by doing the following:

# login to mysql
mysql -u root -p (prompts for password)
SET GLOBAL general_log = 'OFF';
# log file may now be renamed/moved/deleted
# then restart logging
SET GLOBAL general_log = 'ON';

Finally the MySQL manual states that you can simply rename (or delete) the log file and then FLUSH LOGS:

cd /path/to/datadir
mv log-file.name log-file.name.old
# login to mysql
mysql -u root -p (prompts for password)
# creates a new file with log-file.name

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.