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

Complete steps to implement face recognition login in Ubuntu

1. Install Howdy: howdy project address sudo add-...

Linux server quick uninstall and install node environment (easy to get started)

1. Uninstall npm first sudo npm uninstall npm -g ...

Uniapp's experience in developing small programs

1. Create a new UI project First of all, our UI i...

Detailed explanation of the solution to permission denied in Linux

Permission denied: The reason for this is: there ...

Detailed explanation of the difference between tinyint and int in MySQL

Question: What is the difference between int(1) a...

Three ways to configure Nginx virtual hosts (based on domain names)

Nginx supports three ways to configure virtual ho...

Vue uses mixins to optimize components

Table of contents Mixins implementation Hook func...

Detailed explanation of gcc command usage under Linux system

Table of contents 1. Preprocessing 2. Compilation...

Analysis of the principle of Vue nextTick

Table of contents Event Loop miscroTask (microtas...

How to install and configure MySQL and change the root password

1. Installation apt-get install mysql-server requ...

Example sharing of anchor tag usage in HTML

Anchor tag usage: Linking to a specific location i...