4

I have configured the database using SET GLOBAL binlog_expire_logs_seconds = 259200; query to purge binary logs older then 3 days. Using MySQL 8.0.22. This does not seem to have any effect. bin logs are accumulating under /var/lib/mysq/dbname-bin.000xx files. Executing

PURGE BINARY LOGS BEFORE '2020-.......' 

works, but I would like the DB engine to purge those logs on its own without myself calling it. Otherwise binlogs take most of the disk space. Please suggest.

rubenhak
  • 830
  • 2
  • 10
  • 28
  • 1
    FYI the binlogs are not pruned immediately when they are older than the time period. They are pruned when mysqld opens a new binlog file, either because the current log file fills up to the max size, or when you run FLUSH LOGS. So it depends on how fast your binlogs are filling. You might see no binlogs expire for days, if the server is still writing to the same binlog file – Bill Karwin Dec 29 '20 at 01:22

1 Answers1

5

I had the same problem (but on Windows 10), I edited my.ini located in c:/xampp/mysql/bin and added the following:

binlog_expire_logs_seconds=60

Does this work for you?

LarryN
  • 216
  • 1
  • 2
  • 12
  • 3
    Just for completeness, it has to be under "[mysqld]" section. In linux machine it has to be in *.cnf files in corresponding directory. – rubenhak Dec 30 '20 at 02:23
  • 60 seconds may be a bit low. MySQL's default for `binlog_expire_logs_seconds` is 2592000. [[source](https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_expire_logs_seconds)] – pbarney Jan 12 '22 at 17:59