Skip to content

How to Remove/PURGE BINARY LOGS in MySQL & MariaDB

This article will help you Remove or PURGE BINARY LOGS in MySQL & MariaDB

Steps
2
Category
Databases
Covers
MariaDB, MySQL
On this page 2 steps

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.

Step 1 of 2List 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 of 2PURGE 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.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

2 Comments

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

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top