Indonesia Website Awards
Indonesia Website Awards

Binary Log in MySQL serves to store the entire series of queries that run on MySQL. Whether it’s a DDL, DML or DCL query, it will be stored in the mysql binary log. This Binary Log can gradually fill the storage capacity on your server if it is not managed at all. Therefore, I want to share information about how to clear mysql binary logs.

Query to clear MySQL Binary Logs

To clear the binary log, you must do so using a query. Don’t try to delete binary log files manually, because it can cause instability on your database server. First of all go to the mysql console or mysql editor using root access. then you can run one of the following queries as needed :

#Delete binary logs until 7th file (you can change the number)
PURGE BINARY LOGS TO 'mysql-bin.007';

#Delete bianry logs before specific datetime 
PURGE BINARY LOGS BEFORE '2021-06-01 00:00:00';

 

Disabling MySQL Binary Logs

If you feel you don’t need binary logs, you can disable them. It’s easy, find and open the MySQL configuration file. it’s usually in /etc/my.cnf , then add this under the [mysqld] section :

# Turn off binary log MySQL
--skip-log-bin 
# or 
--disable-log-bin

Save, then restart the MySQL service.

 

Save Binary Log for a certain time

If you want the mysql binary log to be saved for a certain time, you can do that. The method is also easy, you just add this under the [mysqld] section in your MySQL configuration file:

# make binary log expired in 3 days (example)
expired_logs_days = 3 
# limit the amount of data not more than 500mb
max_binlog_size = 500M

Save, then restart the MySQL service.

Yep, that’s an easy way how to clear mysql binary logs that I can share. Hopefully this information is useful, Thank you 😀

 

Read Also :

 

Categories: Database

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *