- Home
- Blogs
- George Boobyer's blog
- Binary logs are filling up my Mac - Help!
Binary logs are filling up my Mac - Help!
A colleague of mine was running out of disc space on his development machine and on inspecting the disk space usage (use - www.derlien.com) found that MySQL was using up the bulk of the disk.
It reminded me that I solved this sometime ago and had an automated solution in place - so thought I should share - It is a real 'do your self a favour' tip! (I originally discovered this at http://www.cyberciti.biz/faq/what-is-mysql-binary-log/ - so much of this comes from that page)
Binary logs are used for data replication and recovery. They do build up so it is worth clearing them every now and then.
Basically out of the box MySQL is set up to log to a series of rolling binary log files (http://dev.mysql.com/doc/refman/5.1/en/binary-log.html) - These build up over time and eat your disk.
Update: I often get asked where these files actually are - Look in /usr/local/mysql/data (note that the mysql portion maybe a version number e.g. /usr/local/mysql-5.5.16-osx10.6-x86_64/data) - if in doubt look in your my.cnf for the path to the data files) - It can be usefull to see the actual files just to see the issue - but DON'T DELETE THEM!
In most cases on a dev box you can simply turn these off.
But here are some ways to clear the files that are there all ready - Don't simply delete them!!
Although the primary use of the binary logs is to replicate the database, in some cases they can be used for recovering the database.
So again - Don't delete them and backup your database.
Whilst you shouldn't delete them it is fine to purge them and to set up sensible expiry times and file sizes.
So in your my.cnf
expire_logs_days = 10
max_binlog_size = 100M
If you don't want binary logging at all
If you don't need logging then you can turn it off (most don't unless you are replicating):
locate and edit your my.cnf (/etc/my.cnf - but may be somewhere else in WAMP/MAMP/XAMP etc)
locate and comment out the line:
log_bin = /var/log/mysql/mysql-bin.log
You also need to remove or comment following lines:
expire_logs_days = 10
max_binlog_size = 100M
Close and save the file. Finally, restart mysql server:
service mysql restart
http://www.cyberciti.biz/faq/what-is-mysql-binary-log/
Purging your binary logs
The MySQL Console:
$ mysql> purge binary logs before '2010-10-01 12:00:00';
Some helpful scripts
At the command line
$ mysql> purge binary logs before '2010-10-01 12:00:00';
You can clear them up to a date or up to a specific log file:
A Bash Script
A Batch file for WAMP
Contact Details
Blue-Bag Ltd
- info [at] blue-bag.com
- Telephone: 0843 2894522
- Blue-Bag HQ:
The Garage, Manor Farm
Chilcompton, Radstock
Somerset, BA3 4HP, United Kingdom - Telephone: (+44) 01761 411542
- Blue-Bag Brighton:
Unit 35 Level 6 North, New England House
New England Street, Brighton
BN1 4GH United Kingdom - Telephone: (+44) 07944 938204
- VAT GB 748125034
- UK Company Reg: 3932829