≡ Menu

MySQL Bin Files Eating Lots of Disk Space


$ mysql -u root -p 'MyPassword' -e "PURGE BINARY LOGS BEFORE '2008-12-15 10:06:06';"

Suggested readings:

MySQL Manual – The binary logs

Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 14 comments… add one }
  • Amr Hamdy December 17, 2008, 6:44 pm

    If you are using
    expire_logs_days = 10
    max_binlog_size = 100M
    You will not need to do purge logs manually .. logs older than 10 days will be purged automatically by mysql server …


  • NiTRo December 24, 2008, 4:30 pm

    Amr Hamdy,
    you’re right but if you disable log_bin, you must purge manually.

    Thanks for this post.

  • Johny June 26, 2009, 7:47 am

    Hi, thanks for the tips

    does it works on innodb too ?

  • Steve Stringer April 22, 2010, 9:33 am

    Awesome tip. My logs were taking up 40 Gigs on my dev server and I had no idea.


  • Music01 May 6, 2010, 7:46 pm

    CURRENT_LOGFILE=$(/usr/bin/mysql -u root -p -S -e "SHOW SLAVE STATUS\G" | awk '$1 == "Master_Log_File:" {print $2}')
    echo "Purging Master Logs before ${CURRENT_LOGFILE}"
    /usr/bin/mysql -uroot -p -h -P -e "PURGE MASTER LOGS TO '${CURRENT_LOGFILE}'"
    echo "Purging Slave Logs before Current Log'"
    /usr/bin/mysql -uroot -p -h -S -e "purge binary logs before now();"
    exit $?

  • Aaron February 23, 2011, 4:43 pm

    Hi, just a small correction:
    About the High availability / replication section. It states that the Master sends the binary logs to the slave. However, it’s actually the slave that pulls the log/data from the master.

    “Each slave that connects to the master requests a copy of the binary log. That is, it pulls the data from the master, rather than the master pushing the data to the slave”
    Source: http://dev.mysql.com/doc/refman/5.0/en/replication-implementation.html

  • cangshubao October 13, 2011, 10:46 am


    could you tell me how to perform the data recovery operations by these files

  • Katie @ StylishandTrendy July 11, 2012, 12:08 pm

    Alternatively, you can try this mysql> PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);

    This deletes all logs older than 7 days.

  • Katie @ StylishandTrendy July 11, 2012, 12:09 pm

    Alternatively we can simply use this command


    It deletes all old logs older than 7 days.

  • linux7802 August 7, 2012, 10:59 am

    nice information ….

  • Gopalji varshneya August 31, 2013, 11:57 am


  • Ganeshbabu March 3, 2015, 6:44 am

    Hi Friends, is it possiable to setup a master, slave replication without binlog process… any idea pls… give me asap.

    • Alex Ostrem August 7, 2015, 6:35 pm

      Set up replication…without the logs it uses for replication to happen? No. If the master doesn’t log, there is nothing for the slave to download and apply.

  • bitkahuna December 13, 2015, 6:19 pm

    great article, thanks!

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , , , ,