我的 mysql.general_log 表变得太大了吗?

发布于 2025-01-07 14:46:29 字数 313 浏览 3 评论 0原文

我最近刚刚升级到 MySQL 5.1.6,以便利用将常规日志保存到表的功能 ->即 mysql.general_log。一旦我这样做了,我立即惊讶地发现有多少查询实际上正在访问我们的系统。从第一个小时开始,我的通用日志表中有大约 40,000 行。我还没有发现 MySQL 文档上写有关于是否有一般日志表大小限制的内容。

让这个通用日志以这样的速度增长有问题吗?

如果出现尺寸问题,如何处理?

如果存在尺寸问题,是否有一些公认的做法来处理尺寸问题?

我是否应该经常创建一个事件来清除表并将数据保存到文件中?

非常感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情绪少女 2025-01-14 14:46:29

我对我的日志文件做了类似的事情。我只对保留最后 24 小时感兴趣,但您可以调整事件以创建存档表等。它不会记录事件运行所需的几秒钟,但我不介意。

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

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
听不够的曲调 2025-01-14 14:46:29

General_log 表默认使用 CSV 引擎,它实际上只是驱动器上的完整 CSV 文件,但可以通过 SQL 访问。这意味着它的大小限制是文件系统上文件的大小限制。

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.

空城旧梦 2025-01-14 14:46:29

您应该使用一些实用程序,例如 mysql-log-rotate http://dev.mysql.com/doc/refman/5.0/en/log-file-maintenance.html 用于轮换日志文件。

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.

孤蝉 2025-01-14 14:46:29

不确定这是否是最佳实践,但这是我的解决方案:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文