Mysql correctly clears binlog in two ways: mysqlbinlog

Source: Internet
Author: User

Mysql correctly clears binlog in two ways: mysqlbinlog

Mysq correctly clears binlog logs

Preface:

The binlog log in MySQL records data changes in the database, which facilitates data recovery based on time points and locations. However, binlog also increases and occupies a large disk space. Therefore, correct and secure methods should be used to clear unused logs.

Method 1: manually clear binlog

Preparations before cleaning:

① Check which binlog file is used by the master database and slave Database

show master status\G show slave status\G  

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

Start to delete binlog:

Purge master logs before '2017-09-01 17:20:00 '; // Delete the binlog log file 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

Note:

The time and file name cannot be written incorrectly, especially the sequence numbers in the year and file names in the time, to prevent accidental deletion of the binlog in use !!!

Do not delete the binlog in use !!!

With this syntax, the corresponding file and the corresponding path in the mysql-bin.index are deleted.

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

Mysql> show variables like 'expire _ logs_days '; + ------------------ + ------- + | Variable_name | Value | + -------------------- + ------- + | expires | 0 | + ------------------ + ------- + mysql> set global expire_logs_days = 30;

Note:

The expiration time should be set appropriately. For master-slave replication, the expiration time should be determined based on the slave database delay. This prevents the master database from being deleted due to expiration before the binlog is uploaded to the slave database, causing the master to be inconsistent !!!

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.