Difference between revisions of "delete mysql bin files to clear space"

From thelinuxwiki
Jump to: navigation, search
(Created page with " 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.inde...")
 
 
Line 31: Line 31:
 
taken from...
 
taken from...
  
[https://www.geekdecoder.com/delete-mysql-bin-files-safely/]
+
[https://www.geekdecoder.com/delete-mysql-bin-files-safely/ https://www.geekdecoder.com/delete-mysql-bin-files-safely/]
  
 
[[category:mysql]]
 
[[category:mysql]]

Latest revision as of 16:11, 17 November 2023

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

https://www.geekdecoder.com/delete-mysql-bin-files-safely/