Is my mysql.general_log table getting too big?
Asked Answered
R

4

6

I just recently upgraded to MySQL 5.1.6 in order to take advantage of the ability to save the general log to a table -> i.e. mysql.general_log. Once i did this I was immediately surprised how many queries are actually hitting our system. I have about 40,000 rows in this general log table from the first hour. I haven't found it written on the MySQL docs about if there is a general log table size limit.

Is there a problem to letting this general log grow at this rate?

If there is a size problem, how to deal with it?

Are there some accepted practices how to deal with a size problem if there is one?

Should I make an event to purge the table and save the data to a file every so often?

Thanks a lot for the help!

Reservation answered 18/2, 2012 at 16:41 Comment(1)
One thing you should be aware of, is that running general query log in production environment is not recommended. The performance impact can be pretty high, especially in high concurrency situations.Enroll
P
6

The general_log table by default uses the CSV engine, which is literally just a full-blown CSV file on your drive, but can be accessed via SQL. This means its size limit is the size limit of files on your file system.

Parallel answered 18/2, 2012 at 16:51 Comment(0)
T
9

I do something like this for my log file. I'm only interested in keeping the last 24 hours, but you could tweak the event to create archive tables, etc. It won't log for the few seconds it takes the event to run, but I don't mind.

CREATE EVENT `prune_general_log` ON SCHEDULE
EVERY 1 DAY STARTS '2013-10-18'
ON COMPLETION NOT PRESERVE
ENABLE
COMMENT 'This will trim the general_log table to contain only the past 24 hours of logs.'
DO BEGIN
  SET GLOBAL general_log = 'OFF';
  RENAME TABLE mysql.general_log TO mysql.general_log2;
  DELETE FROM mysql.general_log2 WHERE event_time <= NOW()-INTERVAL 24 HOUR;
  OPTIMIZE TABLE general_log2;
  RENAME TABLE mysql.general_log2 TO mysql.general_log;
  SET GLOBAL general_log = 'ON';
END
Tannenwald answered 18/10, 2013 at 21:16 Comment(0)
P
6

The general_log table by default uses the CSV engine, which is literally just a full-blown CSV file on your drive, but can be accessed via SQL. This means its size limit is the size limit of files on your file system.

Parallel answered 18/2, 2012 at 16:51 Comment(0)
T
1

You should use some utility like mysql-log-rotate http://dev.mysql.com/doc/refman/5.0/en/log-file-maintenance.html for rotating log file.

Terle answered 18/2, 2012 at 16:49 Comment(1)
Unfortunately I am running on a Windows server, it says in the documentation this is included on Linux (Red Hat) installations.Reservation
C
0

Not sure if this is best practice but this was my solution:

DATE=$(date +"%Y%m%d%H%M")
mv general_log.CSV general_log.${DATE}.csv  # move the log table file
sudo -u mysql -g mysql touch general_log.CSV  # create a new log table file with correct owner and group
mysql -u root -e "FLUSH TABLE mysql.general_log"  # flush the log table
Cannibal answered 23/11, 2018 at 19:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.