Expiring MySQL Transaction Logs (mysql-bin.[number]) to Free Disk Space

  • 7019204
  • 03-Mar-2015
  • 07-Aug-2017


Retain 3.x
MySQL 5.x


I'm almost out of disk space on my Retain server.  I looked at the data directory and noticed dozens of files that were 1G each called mysql-bin.[number].  Do I need these files?  Can I delete some of them?


This knowledgebase (KB) article is provided for informational purposes only and as a courtesy service to you, our customer. GWAVA Technical Support does not have any database administration (DBA) expertise, nor does it provide DBA services or support. GWAVA is not responsible for the results of implementing any of the concepts contained in this KB article. Implementation of any of the concepts suggested in this KB article shall be done entirely at your own and sole risk, and GWAVA does not provide any kind of warranties whatsoever resulting from your decision of implementing any of the KB article’s concepts. It is up to you to do any research and to ensure yourself that any implementation and setup of any of the KB article’s concepts in your database system is correctly and properly executed. It is imperative that you have backups of your database system and storage directory before making any implementation. If you don’t have any DBA expertise, you should consult with a DBA expert before any implementation of the KB article’s concepts.  Under no circumstances, shall GWAVA, or any of its employees, be liable, in contract, tort, delict or otherwise, whether negligence is provable or not, for any direct, indirect, incidental, special, punitive, consequential or other damages, loss, cost or liability whatsoever that would result from or are related to the implementation of any of the concepts suggested in the KB article.

To the extent permitted by applicable law, GWAVA shall not be liable to you for any special, consequential, direct, indirect or similar damages, including any loss of data, arising out from migrating any type of messages, attachments, database, metadata in your Retain system to another server and/or location.


These files are MySQL transaction logs and can be used to restore transactions that were applied to the Retain database.  These logs are an essential part of your data loss prevention, but any log prior to a database backup is no longer needed.

It is a best practice to expire the logs, setting the number of days to keep these logs just slightly longer than your backup period.  So, if I were backing up my database every 7 days, I would expire my logs after 10 days or some number like that.

Simply edit the MySQL configuration file (my.cnf on Linux systems, my.ini on Windows).

Make sure that the line "log-bin = mysql-bin" is uncommented - this is what enables transaction logging, which is recommended; then, add this line below it:

expire_logs_days = 10

Then restart MySQL:  rcmysql restart

You can also use this query to remove current logs: https://dev.mysql.com/doc/refman/5.6/en/purge-binary-logs.html

More information on the Binary Log: http://dev.mysql.com/doc/refman/5.6/en/binary-log.html

Additional Information

This article was originally published in the GWAVA knowledgebase as article ID 2489.