MySQL

Can I delete MySQL-bin files?

Voiced by Amazon Polly

There is a concise answer to this question: NO.

You should not delete these files from the OS. The easiest way to handle the issue is to let MySQL do the work for you.

The file mysql-bin.[index] keeps a list of all binary logs MySQLd has generated and auto-rotated. The mechanisms for cleaning out the binlogs in conjunction with mysql-bin.[index] are:

PURGE BINARY LOGS TO 'binlog.001486';
PURGE BINARY LOGS BEFORE 'datetimestamp';

The first example will clear all binary logs before the binlog file binlog.001486. The second will clear any log before the timestamp you specified.

For example;

PURGE BINARY LOGS TO 'binlog.001486';

We erase all binary logs before binlog.001486

if we run:

PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 3 DAY) + INTERVAL 0 SECOND;

This will erase all binary logs before midnight three days ago.

To have binlog rotated automatically and keep three days worth of logs, use this command:

SET GLOBAL expire_logs_days = 3;

add this to /etc/my.cnf

[mysqld]
expire_logs_days=3

Similar Posts

Leave a Reply