How to remove old mysql-bin logs

Hi Techrunnr Readers, this document deals with how to remove old mysql-bin logs.
Mysql Bin log file is a binary file which records all the modification made to Mysql server instance. In the worst case, this Binary files are used for recovery of craased mysql server. Mysql server replication is fully based upon the binary logs.

Sometimes we have to remove the binary files due to low disk space in mysql server.

1. List Binary Files
First list all the binary files,

ls -a /var/lib/mysql

 


-rw-rw—- 1 mysql mysql 1073779688 Jan 31 07:42 mysql-bin.000310
-rw-rw—- 1 mysql mysql 1073761025 Jan 31 08:00 mysql-bin.000311
-rw-rw—- 1 mysql mysql 1073746040 Jan 31 08:22 mysql-bin.000312
-rw-rw—- 1 mysql mysql 1073759833 Feb 1 04:31 mysql-bin.000313
-rw-rw—- 1 mysql mysql 679581946 Feb 1 13:30 mysql-bin.000314
-rw-rw—- 1 mysql mysql 1073744048 Mar 2 11:00 mysql-bin.000315
-rw-rw—- 1 mysql mysql 1073760496 Apr 3 11:00 mysql-bin.000316
-rw-rw—- 1 mysql mysql 650118832 Apr 12 10:34 mysql-bin.000317
-rw-rw—- 1 mysql mysql 1073744354 Apr 27 07:30 mysql-bin.000318
-rw-rw—- 1 mysql mysql 1073744113 May 8 07:30 mysql-bin.000319
-rw-rw—- 1 mysql mysql 1239410046 May 9 06:55 mysql-bin.000320
-rw-rw—- 1 mysql mysql 1073756632 May 16 04:30 mysql-bin.000321
-rw-rw—- 1 mysql mysql 1073749816 May 21 11:00 mysql-bin.000322
-rw-rw—- 1 mysql mysql 1073746641 May 24 11:00 mysql-bin.000323
-rw-rw—- 1 mysql mysql 1073749671 Jun 5 05:30 mysql-bin.000324
-rw-rw—- 1 mysql mysql 1073745577 Jun 22 11:00 mysql-bin.000325
-rw-rw—- 1 mysql mysql 1073756387 Jul 10 08:30 mysql-bin.000326
-rw-rw—- 1 mysql mysql 1073748112 Jul 14 11:00 mysql-bin.000327
-rw-rw—- 1 mysql mysql 1073748496 Jul 18 09:30 mysql-bin.000328
-rw-rw—- 1 mysql mysql 1073753760 Jul 20 07:30 mysql-bin.000329
-rw-rw—- 1 mysql mysql 1073743130 Jul 23 05:30 mysql-bin.000330
-rw-rw—- 1 mysql mysql 1073743485 Jul 25 04:30 mysql-bin.000331
-rw-rw—- 1 mysql mysql 629417162 Jul 26 09:30 mysql-bin.000332

2. Purge binary logs
Here we have two commands to delete the old files, choose the command depends upon your situation.

Delete binary log file mysql-bin.000330 or older files.

mysql> PURGE BINARY LOGS TO ‘mysql-bin.000330’;

 

that’s IT now have successfully removed old MySQL binary logs

© 2018, Techrunnr. All rights reserved.

Questions Answered
Articles Written
Overall Points

prabhin

He is Technical professional. He is a person who loves to share tricks and tips on the Internet. He Posts what he does!!

Leave a Reply

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

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.