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

Detailed explanation of scheduled tasks for ordinary users in Linux

Preface Ordinary users define crontab scheduled t...

Introduction to CSS style classification (basic knowledge)

Classification of CSS styles 1. Internal style --...

JS uses canvas technology to imitate echarts bar chart

Canvas is a new tag in HTML5. You can use js to o...

How to visualize sketched charts in Vue.js using RoughViz

introduce A chart is a graphical representation o...

The difference and usage of distinct and row_number() over() in SQL

1 Introduction When we write SQL statements to op...

Linux centOS installation JDK and Tomcat tutorial

First download JDK. Here we use jdk-8u181-linux-x...

Explanation of nginx load balancing and reverse proxy

Table of contents Load Balancing Load balancing c...

Image hover toggle button implemented with CSS3

Result:Implementation Code html <ul class=&quo...

A brief discussion on three methods of asynchronous replication in MySQL 8.0

In this experiment, we configure MySQL standard a...

A brief analysis of how to upgrade PHP 5.4 to 5.6 in CentOS 7

1. Check the PHP version after entering the termi...

Complete steps to quickly configure HugePages under Linux system

Preface Regarding HugePages and Oracle database o...

JavaScript to achieve progress bar effect

This article example shares the specific code of ...