Disable MySQL binary logging

MySQL can keep a so-called binary log of transactions, which keeps track of all updates to the database. It is used for database restoration and replication.

The logs can grow very quickly in size. At the time of writing, my logs take up around 68G.

I use the database in question as a dump for backups taken from various other servers, so it is not necessary for me to keep transaction logs.

How to turn off binary logging

Edit your my.cnf file and comment out the log-bin option. Also make sure that expire_log_days option is missing or commented out.

...
#log-bin
...
#expire_logs_days = 10
...

Then restart mysql.

How to delete the binary logs

On Gentoo, the logs are located in /var/lib/mysql.

If you have not configured a custom basename for the log files, it is likely they are stored using your domain name, e.g. localhost-bin.000001. I believe older versions of MySQL used “mysql” as the basename, so look for mysql-bin.000001. There will also be an index file with a .index extension.

bpc ~ # cd /var/lib/mysql
bpc mysql # ls
auto.cnf           mysqld-bin.000278  mysqld-bin.000301  mysqld-bin.000324
...cut...          mysqld-bin.000279  mysqld-bin.000302  mysqld-bin.000325
...cut...          mysqld-bin.000280  mysqld-bin.000303  mysqld-bin.000326
ibdata1            mysqld-bin.000281  mysqld-bin.000304  mysqld-bin.000327
ib_logfile0        mysqld-bin.000282  mysqld-bin.000305  mysqld-bin.000328
ib_logfile1        mysqld-bin.000283  mysqld-bin.000306  mysqld-bin.000329
...cut...          mysqld-bin.000284  mysqld-bin.000307  mysqld-bin.000330
...cut...          mysqld-bin.000285  mysqld-bin.000308  mysqld-bin.000331
...cut...          mysqld-bin.000286  mysqld-bin.000309  mysqld-bin.000332
...cut...          mysqld-bin.000287  mysqld-bin.000310  mysqld-bin.000333
mysql              mysqld-bin.000288  mysqld-bin.000311  mysqld-bin.000334
mysqld-bin.000266  mysqld-bin.000289  mysqld-bin.000312  mysqld-bin.000335
mysqld-bin.000267  mysqld-bin.000290  mysqld-bin.000313  mysqld-bin.000336
mysqld-bin.000268  mysqld-bin.000291  mysqld-bin.000314  mysqld-bin.index
mysqld-bin.000269  mysqld-bin.000292  mysqld-bin.000315  performance_schema
mysqld-bin.000270  mysqld-bin.000293  mysqld-bin.000316  ...cut...
mysqld-bin.000271  mysqld-bin.000294  mysqld-bin.000317  ...cut...
mysqld-bin.000272  mysqld-bin.000295  mysqld-bin.000318  ...cut...
mysqld-bin.000273  mysqld-bin.000296  mysqld-bin.000319  ...cut...
mysqld-bin.000274  mysqld-bin.000297  mysqld-bin.000320  ...cut...
mysqld-bin.000275  mysqld-bin.000298  mysqld-bin.000321
mysqld-bin.000276  mysqld-bin.000299  mysqld-bin.000322
mysqld-bin.000277  mysqld-bin.000300  mysqld-bin.000323

(The ...cut... are my databases that I’ve removed from the listing).

To delete the logs, do the following in mysql, replacing mysqld-bin.000336 with the oldest log that you’d like to keep:

purge binary logs to 'mysqld-bin.000336';

This will get rid of all logs from .000001 to .000336.

bpc mysql # ls
auto.cnf         ib_logfile1       mysql               ...cut...
...cut...        ...cut...         mysqld-bin.000336   ...cut...
...cut...        ...cut...         mysqld-bin.index    ...cut...
ibdata1          ...cut...         performance_schema  ...cut...
ib_logfile0      ...cut...         ...cut...

References

Last modified: 27/11/2016 Tags: (none)

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top