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.


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
# login to mysql
mysql -u root -p (prompts for password)
# creates a new file with

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.