在 MySQL 中,如何删除/刷新/清除所有不需要的日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7381320/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:02:52  来源:igfitidea点击:

In MySQL, how can I delete/flush/clear all the logs that are not necessary?

mysqlloggingclear

提问by Erwin Mayer

I have tried several commands (FLUSH LOGS, PURGE MASTER) but none deletes the log files (when previously activated) or the log tables (mysql/slow_log.CSV and mysql/general_log.CSV and their .frm and .CSM counterparts).

我尝试了几个命令(FLUSH LOGS、PURGE MASTER),但没有一个会删除日志文件(之前激活时)或日志表(mysql/slow_log.CSV 和 mysql/general_log.CSV 以及它们的 .frm 和 .CSM 对应文件)。

SHOW BINARY LOGS returns "You are not using binary logging".

SHOW BINARY LOGS 返回“您没有使用二进制日志记录”。

Edit: I found this simple solution to clear the table logs (but not yet the file logs using a mysql command):

编辑:我找到了这个简单的解决方案来清除表日志(但还没有使用 mysql 命令清除文件日志):

TRUNCATE mysql.general_log;
TRUNCATE mysql.slow_log;

回答by Bill Karwin

FLUSH LOGS just closes and reopens log files. If the log files are large, it won't reduce them. If you're on Linux, you can use mvto rename log files while they're in use, and then after FLUSH LOGS, you know that MySQL is writing to a new, small file, and you can remove the old big files.

FLUSH LOGS 只是关闭并重新打开日志文件。如果日志文件很大,它不会减少它们。如果您使用的是 Linux,您可以mv在日志文件正在使用时对其进行重命名,然后在 FLUSH LOGS 之后,您就知道 MySQL 正在写入一个新的小文件,您可以删除旧的大文件。

Binary logs are different. To eliminate old binlogs, use PURGE BINARY LOGS. Make sure your slaves (if any) aren't still using the binary logs. That is, run SHOW SLAVE STATUS to see what binlog file they're working on, and don't purge that file or later files.

二进制日志是不同的。要消除旧的二进制日志,请使用PURGE BINARY LOGS。确保您的从站(如果有)没有仍在使用二进制日志。也就是说,运行 SHOW SLAVE STATUS 以查看他们正在处理的二进制日志文件,并且不要清除该文件或以后的文件。

Also keep in mind that binlogs are useful for point-in-time recovery in case you need to restore from backups and then reapply binlogs to bring the database up to date. If you need to use binlogs in this manner, don't purge the binlogs that have been written since your last backup.

还要记住,如果您需要从备份中恢复,然后重新应用二进制日志以使数据库保持最新状态,则二进制日志对于时间点恢复很有用。如果您需要以这种方式使用二进制日志,请不要清除自上次备份以来已写入的二进制日志。

回答by Joan-Diego Rodriguez

If you are on amazon RDS, executing this twice will do the trick:

如果你在亚马逊 RDS 上,执行两次就可以了:

PROMPT> CALL mysql.rds_rotate_slow_log;
PROMPT> CALL mysql.rds_rotate_general_log;

Source: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html

来源:http: //docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html

回答by kasi

It seems binary logging is not enabled in your server .And i guess you want to delete the old log files which were used/created at the time of binary logging is enabled . you can delete them manually using 'rm' command if you want . if you want to enable the binary logging you can do the same by updating the configuaration file ( but it needs restart of the server if it is already running) . You can refer below links. http://dev.mysql.com/doc/refman/5.0/en/replication-options-binary-log.html#option_mysqld_log-binhttp://dev.mysql.com/doc/refman/5.0/en/replication-options-binary-log.html#sysvar_log_bin

您的服务器中似乎未启用二进制日志记录。我猜您想删除在启用二进制日志记录时使用/创建的旧日志文件。如果需要,您可以使用“rm”命令手动删除它们。如果你想启用二进制日志,你可以通过更新配置文件来做同样的事情(但如果它已经在运行,则需要重新启动服务器)。您可以参考以下链接。 http://dev.mysql.com/doc/refman/5.0/en/replication-options-binary-log.html#option_mysqld_log-bin http://dev.mysql.com/doc/refman/5.0/en/replication -options-binary-log.html#sysvar_log_bin