Skip to content

Instantly share code, notes, and snippets.

@dharma017
Created August 20, 2024 08:41
Show Gist options
  • Save dharma017/451354f48aa3ad006ac3e30690b36c79 to your computer and use it in GitHub Desktop.
Save dharma017/451354f48aa3ad006ac3e30690b36c79 to your computer and use it in GitHub Desktop.

Revisions

  1. dharma017 created this gist Aug 20, 2024.
    26 changes: 26 additions & 0 deletions delete-mysql-log-file
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    Erase all binary logs before midnight 3 days ago.

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

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

    mysql> SET GLOBAL expire_logs_days = 3;

    then add this to /etc/my.cnf

    [mysqld]
    expire_logs_days=3

    and mysqld will delete them logs for you

    Updated way:

    touch /etc/mysql/mysql.conf.d/binlog_expiration.cnf

    Add following content in binlog_expiration.cnf file

    [mysqld]

    # Three days: 24*60*60*3
    #binlog_expire_logs_seconds=259200
    skip-log-bin