delete mysql bin files to clear space

From thelinuxwiki
Revision as of 16:11, 17 November 2023 by Nighthawk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 ‘binlogname’;

PURGE BINARY LOGS BEFORE ‘datetimestamp’;

These will clear all binary logs before the binlog or timestamp you just specified.

erase all binary logs before ‘mysql-bin.000223’.

mysql> PURGE BINARY LOGS TO 'mysql-bin.000223';

run

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

this will erase all binary logs before midnight 3 days ago.

If you want to have binlog rotated away automatically and keep 3 days woth, simply set this:


mysql> SET GLOBAL expire_logs_days = 3;

add this /etc/my.cnf

[mysqld]

expire-logs-days=3

and mysqld will delete them logs for you

taken from...

[1]