Delete massive MySQL binlog operations

Source: Internet
Author: User

The following articles mainly describe the actual operation solution for clearing and deleting large MySQL binlogs. We are operating on cleaning and deleting large MySQL binlogs In the MySQL master/slave architecture environment, the following describes the specific content of the article.

Problem: the hard disk of the master database is less than s.

Cause: a large number of bin binary logs under MySQL var, more than 200 GB

Objective: To safely delete MySQL binlog

Method: Search for the keyword "MySQL binfile deletion" on the Internet ~~

Related statements:

 
 
  1. PURGE {MASTER | BINARY} LOGS TO 'log_name'  
  2. PURGE {MASTER | BINARY} LOGS BEFORE 'date'  

Deletes all binary logs listed in the log index before the specified log or date. These logs will also be deleted from the list of records in the log index file, so that the given log becomes the first.

For example:

 
 
  1. PURGE MASTER LOGS TO 'MySQL-bin.010';  
  2. PURGE MASTER LOGS BEFORE '2003-04-02 22:46:26'; 

The date argument for the BEFORE variable can be in the 'yyyy-MM-DD hh: mm: ss' format. Both MASTER and BINARY are synonyms.

If you have an active slave server that is currently reading one of the logs you are trying to delete, this statement does not work, but fails with an error. However, if the slave server is slave and you happen to have cleared one of the logs it wants to read, the slave server cannot be copied after it is started. This statement can be run safely when the slave server is being copied. You do not need to stop them.

To delete a large MySQL binlog, follow these steps:

1. Use show slave status on each SLAVE server to check which log it is reading.

2. Use show master logs to obtain a series of LOGS on the MASTER server.

3. Identify the earliest logs among all slave servers. This is the target log. If all slave servers are updated, this is the last log in the list.

4. Back up all the logs you want to delete. This step is optional, but is recommended .)

5. Clear all logs, but not the target logs.

Practice:

Slave database ---

MySQL> show slave status \ G;

......

Master_Log_File: tc-ns-comment-db00-bin.000162

Relay_Master_Log_File: tc-ns-comment-db00-bin.000162

......

Under the master database ---

MySQL> show master log;

............ Heaps

MySQL> purge master logs to 'tc-ns-comment-db00-bin.000070 ';

...... Wait n long time

 
 
  1. MySQL>quit  
  2. $du -sh ./  

A lot of g is reduced, and the world is clean ~~

The above content describes how to delete a large MySQL binlog, hoping to help you in this regard.


 

Related Article

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.