MySQL 清除MySQL通用日志表,安全吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14670075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clear MySQL General Log Table, Is It Safe?
提问by Rana
I server I am working on, general mysql log table is taking near 200GB space, which is huge. So, I am planning to clear it up with:
我正在处理的服务器,一般的 mysql 日志表占用了近 200GB 的空间,这是巨大的。所以,我打算用以下方法清理它:
TRUNCATE table mysql.general_log
Is it ok? Will it cause any issue? I am concerned as the server is live and big application. Thanks.
可以吗?它会导致任何问题吗?我很担心,因为服务器是实时的并且是大型应用程序。谢谢。
回答by Big Data DBA
It will definitely cause a problem unless it is disabled and then you truncate. If you truncate while it is enabled. Truncate will lock the table if table is huge, since mysql.general_log engine is either CSV or MyISAM ,meanwhile newly made entries will try to be written in general log table causing a lock for all the connection and will eventually end up with "Too Many Connection". So for safety do like this
它肯定会导致问题,除非它被禁用然后你截断。如果在启用时截断。如果表很大,截断将锁定表,因为 mysql.general_log 引擎是 CSV 或 MyISAM,同时新创建的条目将尝试写入通用日志表,导致所有连接锁定,最终以“太多联系”。所以为了安全起见这样做
mysql> SET GLOBAL general_log=OFF;
mysql> TRUNCATE table mysql.general_log;
mysql> SET GLOBAL general_log=ON;
回答by 0xfded
It won't cause problems, but you will lose all the old log entries, so Ravindra's advice above is good.
它不会引起问题,但您会丢失所有旧的日志条目,因此上面 Ravindra 的建议很好。
You can do a backup with:
您可以使用以下方法进行备份:
mysqldump -p --lock_tables=false mysql general_log > genlog.sql
mysqldump -p --lock_tables=false mysql general_log > genlog.sql
Do you need to have the general log on all the time? I usually only turn it on when I'm troubleshooting performance issues. MySQL logs EVERYTHING there (client connects, disconnects, and EVERY statement). In most systems, the logs get very big very quickly. There is also some performance overhead for this.
您是否需要始终保持常规登录?我通常只在对性能问题进行故障排除时打开它。MySQL 在那里记录一切(客户端连接、断开连接和每个语句)。在大多数系统中,日志很快就会变得很大。这也有一些性能开销。