MySQL Binlogs – How to Temporarily Compress

MySQL

I am currently importing a pretty big MySQL database dump. This takes time and during this time I need some extra disk space. Will I break something in MySQL if I temporarily gzip a couple of it's binlogs? I'm assuming I'm not going to compress binlogs that are purged, nor written, nor read by the MySQL instance.

Example:

$ ls
mysql-bin.000340
mysql-bin.000341
mysql-bin.000342
mysql-bin.000343.gz
mysql-bin.000344.gz
mysql-bin.000345.gz
mysql-bin.000346
mysql-bin.000347
mysql-bin.000348
mysql-bin.index

Best Answer

Yes, it is perfectly safe to do so as long as you donĀ“t gzip the file which is currently written (the last file).

Also in case of a replication setup ensure that the files you are gzipping are already fetched by the slave. You can verify this by checking the output of SHOW SLAVE STATUSon the slave, look here for Master_Log_File, this will give you the logfile of the master which is currently be fetched by the slaves io-thread. Every preceding file is absolutely safe to gzip.