Detailed explanation of MySQL database binlog cleanup command

Detailed explanation of MySQL database binlog cleanup command

Overview

Today I will mainly share how to correctly delete binlog logs from MySQL database. Be careful not to force the use of rm command to clear them. Otherwise, mysq-bin.index will be disordered, which will eventually lead to the failure of the later expire-log-days configuration item.

1. View binlog log

mysql> show binary logs; 


2. Delete all log files before a certain log file

purge binary logs to 'mysql-bin.000035'; 


3. Clean up binlog logs before 2019-09-09 13:00:00

PURGE MASTER LOGS BEFORE '2019-09-09 13:00:00'; 


4. Clean up binlog logs from 3 days ago

PURGE MASTER LOGS BEFORE DATE_SUB(NOW( ), INTERVAL 3 DAY); 
--BEFORE, the date argument of the variable can be in the format 'YYYY-MM-DD hh:mm:ss'. The cleanup here refers to the files from now - 3243600s ago, which is the time when this file was last updated.
--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! ! !
--Do not delete the binlog in use! ! !

5. Reset all logs

reset master; 


6. Manually switch binlog log

flush logs 
--or flush binary logs 


When you delete all binlogs one day and the database does not generate new logs, you can use manual switching to generate them.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • 3 common errors in reading MySQL Binlog logs
  • How to view mysql binlog (binary log)
  • Two ways to correctly clean up mysql binlog logs
  • 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

<<:  Detailed explanation of primitive values ​​and reference values ​​in ECMAScript

>>:  How to use the Linux seq command

Recommend

Example code for implementing triangles and arrows through CSS borders

1. CSS Box Model The box includes: margin, border...

Detailed explanation of the solution to the nginx panic problem

Regarding the nginx panic problem, we first need ...

jQuery implements the function of adding and deleting employee information

This article shares the specific code of jQuery t...

Exploring the Linux Kernel: The Secrets of Kconfig

Get a deep understanding of how the Linux configu...

In-depth study of JavaScript array deduplication problem

Table of contents Preface 👀 Start researching 🐱‍🏍...

One-click installation of MySQL 5.7 and password policy modification method

1. One-click installation of Mysql script [root@u...

Useful codes for web page creation

<br />How can I remove the scroll bar on the...

DIV background semi-transparent text non-translucent style

DIV background is semi-transparent, but the words ...

How to implement the Vue mouse wheel scrolling switching routing effect

A root routing component (the root routing compon...

CSS3 changes the browser scroll bar style

Note: This method is only applicable to webkit-ba...

Linux tutorial on replacing strings using sed command

To replace a string, we need to use the following...

Tomcat first deployment web project process diagram

Put your own web project in the webapps directory...

7 skills that great graphic designers need to master

1》Be good at web design 2》Know how to design web p...

HTML line spacing setting methods and problems

To set the line spacing of <p></p>, us...