Two ways to correctly clean up mysql binlog logs

Two ways to correctly clean up mysql binlog logs

mysql correctly cleans up binlog logs

Preface:

The binlog in MySQL records the changes in the data in the database, which facilitates the time-based and location-based recovery of the data. However, the binlog will also grow larger and take up a lot of disk space. Therefore, it is necessary to use the correct and safe method to clean up some useless logs.

[Method 1] Manually clean up binlog

Preparation before cleaning:

① Check which binlog file the master and slave are using

show master status\G 
show slave status\G

② Before deleting the binlog log, back up the binlog log first, just in case

Start deleting binlog:

purge master logs before'2016-09-01 17:20:00'; //Delete the binlog log files in the log index before the specified date

or

purge master logs to'mysql-bin.000022'; //Delete the binlog log file in the log index of the specified log file

Notice:

The time and file name must not be written incorrectly, especially the year in the time and the serial number in the file name, to prevent the binlog in use from being accidentally deleted! ! !

Never delete a binlog that is in use! ! !

Using this syntax will delete the corresponding files and the corresponding paths in mysql-bin.index.

[Method 2] Set the binlog expiration time to enable the system to automatically delete the binlog file

mysql> show variables like 'expire_logs_days'; 
+------------------+-------+ 
| Variable_name | Value | 
+------------------+-------+ 
| expire_logs_days | 0 | 
+------------------+-------+ 
mysql> set global expire_logs_days = 30; #Set the number of days for binlog to expire

Notice:

The expiration time should be set appropriately. For master-slave replication, the expiration time should be determined based on the delay of the slave database to avoid the master database binlog being deleted due to expiration before being transferred to the slave database, resulting in inconsistency between the master and the slave! ! !

Thank you for reading, I hope it can help you, thank you for your support of this site!

You may also be interested in:
  • Detailed explanation of MySQL database binlog cleanup command
  • 3 common errors in reading MySQL Binlog logs
  • How to view mysql binlog (binary log)
  • Explain MySQL's binlog log and how to use binlog log to recover data
  • Summary of Binlog usage of MySQL database (must read)
  • How to automatically clean up MySQL binlog logs
  • Teach you to automatically restore the log file (binlog) of the MySQL database
  • [MySQL binlog] How to thoroughly parse binlog in Mixed log format in MySQL
  • Detailed explanation of mysql binlog binary log
  • Parsing MySQL binlog

<<:  How to generate Vue user interface by dragging and dropping

>>:  Docker container introduction

Recommend

A brief understanding of the differences between MySQL InnoDB and MyISAM

Preface MySQL supports many types of tables (i.e....

Detailed explanation of CSS style cascading rules

CSS style rule syntax style is the basic unit of ...

Windows 10 + mysql 8.0.11 zip installation tutorial detailed

Prepare: MySQL 8.0 Windows zip package download a...

MySQL transaction isolation level details

serializable serialization (no problem) Transacti...

In-depth analysis of MySQL database transactions and locks

Table of contents 1. Basic Concepts ACID 3.AutoCo...

MySQL 5.7.17 installation and configuration method graphic tutorial

This article shares the installation and configur...

The table tbody in HTML can slide up and down and left and right

When the table header is fixed, it needs to be di...

Mini Programs use Mini Program Cloud to implement WeChat payment functions

Table of contents 1. Open WeChat Pay 1.1 Affiliat...

How to build gitlab on centos6

Preface The original project was placed on the pu...

jQuery plugin to achieve code rain effect

This article shares the specific code of the jQue...

JS version of the picture magnifying glass effect

This article shares the specific code of JS to ac...

Vue's global watermark implementation example

Table of contents 1. Create a watermark Js file 2...

Vue implements adding, displaying and deleting multiple images

This article shares the specific code for Vue to ...