MySQL binlog safe removal

Source: Internet
Author: User

Theoretically, you should add a configuration entry for the Binlog expiration time in the profile/etc/my.cnf, Expire_logs_days = 10

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 yourself First:

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

(Purge: Purge; Clear

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.

Let's say we keep the log for nearly 3 days, so we can

PURGE MASTER LOGS before ' 2010-10-17 00:00:00 ';

Look at the number of files before and after execution:

Before execution:

part2# ls mysql-bin.*|wc-l
243

Execution Purge:

Mysql> PURGE MASTER LOGS before ' 2010-10-17 00:00:00 ';
Query OK, 0 rows affected (0.02 sec)

After execution:

part2# ls mysql-bin.* | Wc-l
88

Can be seen in the 17th before the Binlog all deleted.

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.

By default, MySQL will keep the mysql-bin file, so that at some point, the disk may be full, whether it is possible to delete these files, whether it can be safely deleted, is a problem.

First of all, these files are MySQL log files, if not the master from the copy, it is basically useless, although useless, but not recommended to use the RM command to delete, it may be unsafe, the correct way is to remove the MySQL command.

Mysql-U root-PEnterPassword: Welcometo theMysqlMonitor. Commands End With ; Or\g.Your MysqlConnection IDIs 2819416ServerVersion: 5.5.24-0ubuntu0.12.04.1-Log(Ubuntu)Copyright (C) 2000, 2011, Oracle and/OrIts affiliates. AllRights reserved.Oracle IsA registered trademark ofOracle Corporation and/OrItsaffiliates. OtherNames may trademarks of their respectiveowners.type  ' help; '  or  ' \h ' for Help.type  ' \c '  to clear the current input Statement. Mysql> reset Master;query Ok, 0  rows affected  (3 min  37.65 Sec)           

In fact, the key command is that reset master; this command will empty the Mysql-bin file.

In addition, if your MySQL server does not need to master from the copy, it is recommended to modify the My.cnf file, to set not to generate these files, as long as the deletion of MY.CNF in the following line is possible.

Log-bin=MySQL-bin      

If you need to copy, it is a good idea to control the number of days these log files remain, which can be set by the following configuration:

=7

Indicates that the log is retained for 7 days, so that old logs are automatically cleaned out.

Reference: http://blog.csdn.net/atco/article/details/24259333

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.