MySQL Delete binary log files

Source: Internet
Author: User
Tags mysql delete

One. RESET MASTER

This statement verifies the success of the first configuration of the host machine, with the following steps:

1. Start master and slave, turn on replication (i.e. copy)

NOTE: Replication (copy) is also an important technology for MySQL

2. Run some test statements to see if the data can be copied to slave

3. When the copy is working properly, stop slace then perform reset slave on the slave, removing the unwanted data

4. Perform reset master on master to remove data generated from 2

You can delete all binary logs that are listed in the index file, set the binary log index file back to empty, and create a new binary log file

Please do not execute this statement when there is slave running.

The difference between PURGE MASTER LOGS is 2 points:

1. When the reset MASTER is executed, all binary logs are reset to null files ending with. 000001 numbers are emptied

And purge MASTER LOGS didn't reset it.

2.RESET Master cannot be executed while the standby machine is running and PURGE master LOGS can be executed.

Note: RESET This command should be used with caution only when the initialization of the environment to delete garbage data to use the currently running library is best not to do!!!!

Two. PURGE MASTER LOGS

Grammar

PURGE {MASTER | BINARY} LOGS to ' Log_name '--used to delete the specified log
PURGE {MASTER | BINARY} LOGS before ' date '--used to delete the log before the date, the date argument of the before variable can be ' yyyy-mm-dd hh:mm:ss ' format
such as: (both MASTER and binary are equivalent here)
PURGE MASTER LOGS to ' test-bin.000001 ';
PURGE MASTER LOGS before ' 2011-01-0100:00:00 ';

If you have an active slave, and the Slave is currently reading one of the logs that you are trying to delete from master, this statement will not work, but will fail with an error, if the slave is stopped, and the log that happens to be cleaned is one of the logs it wants to read. These logs cannot be copied after salve is started, and this statement can be run safely when slave is replicating. You do not need to stop them.

To clean up the log, follow these steps:

1. On SLAVE, use show SLAVE status to check which log it is reading.
2. Use show master logs to get a series of logs on Master.
3. Determine the earliest logs in all slave. This is the target log. If all the slave are updated, this is the last log on the list.

4. Make a backup of all logs to be deleted

Three. Specify parameters for automatic cleanup log

The default value for the parameter Expire_logs_days in the MY.CNF configuration file is 0, which means "do not delete automatically"

Possible removal at startup and binary log loops

Syntax: Mysql-u-P executes after entering:

Set GLOBAL expire_logs_days=5;

But it won't take effect immediately.

Need to execute:

1. Implementation of the flush logs;

(Close the current binary log file and create a new one, the name of the new binary log file is added 1 on the current binary file number.) )

2. Or wait for the current log file to fill the set size (restart the server optional)

Expire_logs_days=5--Indicates automatic deletion of logs from 5 days ago

Note: When there is a standby machine must pay attention to the master of the impact of slave.

MySQL Delete binary log files

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.