MySQL binlog safe removal

Source: Internet
Author: User

1. Manually clear the Binlog file

Theoretically, you should add a configuration entry for the Binlog expiration time in the configuration file/etc/my.cnf, Expire_logs_days = ten. but without adding this, the disk has been eaten a lot as more and more binlog are produced. You can delete the Binlog file directly, but you can remove it more safely through the tools provided by MySQL. The Mysql-bin.index file is not updated because purge updates the entries in the Mysql-bin.index and deletes them directly. Mysql-bin.index's role is to speed up the search for binlog files.

Help a bit first 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0020.gif "alt=" J_0020.gif "/>:

mysql> Help Purge
Name: ' PURGE MASTER LOGS '
Description:
Syntax:
PURGE {MASTER | BINARY} LOGS to ' Log_name '
PURGE {MASTER | BINARY} LOGS before ' date '

Deletes all the binary logs listed in the log index prior to the
Specified log or date. The logs also is removed from the list recorded
The log index file, so, the given log becomes the first.

This statement have no effect if the--log-bin option has not been
Enabled.

URL: http://dev.mysql.com/doc/refman/5.0/en/purge-master-logs.html

Examples:
PURGE MASTER LOGS to ' mysql-bin.010 ';
PURGE MASTER LOGS before ' 2003-04-02 22:46:26 ';

Both of these methods are available. The first one is to delete to a file, and the second is to delete it to a certain date.

For example, if we delete the log before 2017-05-31, you can

mysql> PURGE MASTER LOGS before ' 2017-05-31 00:00:00 ';

2. Set Expire_logs_days

# VIM/ETC/MY.CNF//Modify Expire_logs_days,x is the number of days automatically deleted, typically set X to a short point, such as 10
Expire_logs_days = x//The number of days the binary log is automatically deleted. The default value is 0, which means "No automatic deletion"

This method requires a restart of MySQL, appendix for the English instructions for Expire_logs_days

Of course, you can not restart MySQL, turn on MySQL master, directly in MySQL set expire_logs_days

> show binary logs;
> Show variables like '%log% ';
> Set Global expire_logs_days = 10;

Note: It is best to slave up to see the current sync to that Binlog file, with show slave status View. Otherwise, if the master is deleted more, it causes the slave missing log file to cause the data to be inconsistent.


This article is from "Dream Dreams" blog, please be sure to keep this source http://dreamy.blog.51cto.com/12471447/1936959

MySQL binlog safe removal

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.