Erwin Mayer
Erwin Mayer

Reputation: 18670

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

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).

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

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

TRUNCATE mysql.general_log;
TRUNCATE mysql.slow_log;

Upvotes: 30

Views: 106202

Answers (4)

Dinesh vishe
Dinesh vishe

Reputation: 3598

The PURGE BINARY LOGS statement deletes all the binary log files listed in the log index file prior to the specified log file name or date. BINARY and MASTER are synonyms.

To list the binary log files on the server, use SHOW BINARY LOGS.

PURGE BINARY LOGS BEFORE '2024-04-21';

If the expire_logs_days server system variable is not set to 0, the server automatically deletes binary log files after the given number of days. From MariaDB 10.6, the binlog_expire_logs_seconds variable allows more precise control over binlog deletion, and takes precedence if both are non-zero.

Upvotes: 0

Bill Karwin
Bill Karwin

Reputation: 562330

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 mv to 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.

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

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.

Upvotes: 37

kasi
kasi

Reputation: 111

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-bin http://dev.mysql.com/doc/refman/5.0/en/replication-options-binary-log.html#sysvar_log_bin

Upvotes: 1

Joan-Diego Rodriguez
Joan-Diego Rodriguez

Reputation: 2547

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

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

Upvotes: 18

Related Questions