Binary log files contains data about modification’s make by MySQL server. You can see there are multiple binary files will be available on your MySQL server and there will be one .index file which contains names of all binary files to keep track of them.

Advertisement

Step 1. List Binary Files

First list binary log files in your system and find out how old binary log files you want to delete. These files generally located under /var/lib/mysql directory.

# ls -a /var/lib/mysql 

...
-rw-rw---- 1 mysql mysql   3800220 Jul 21 15:15 mysql-bin.000733
-rw-rw---- 1 mysql mysql   1076727 Jul 21 15:40 mysql-bin.000734
-rw-rw---- 1 mysql mysql    263024 Jul 21 15:42 mysql-bin.000735
-rw-rw---- 1 mysql mysql  13895153 Jul 22 00:36 mysql-bin.000736
-rw-rw---- 1 mysql mysql   2717571 Jul 22 01:02 mysql-bin.000737
-rw-rw---- 1 mysql mysql   4080285 Jul 22 03:49 mysql-bin.000738
...

Step 2. PURGE Binary Logs

Now use any one of following commands to delete older binary log files as per your system requirements.

  • Delete binary log file mysql-bin.000735 or older files.
    mysql> PURGE BINARY LOGS TO 'mysql-bin.000735';
    
  • Delete all binary log files created till date “2015-07-21 23:59:59”.
    mysql> PURGE BINARY LOGS BEFORE '2015-07-21 23:59:59';
    

Now list binary log files again, You will find that all older logs has been removed from mysql directory.

Share.

2 Comments

  1. Robi Erwin Setiawan on

    I already login to MySQL using the root account but when executed purge binary.

    It just showed this Query OK, 0 rows affected (0.000 sec).

    And there’s no deleting file

Exit mobile version