Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Secure deletion of binlog for mysql

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. Manually clear the binlog file

In theory, the configuration item for binlog expiration time should be added to the configuration file / etc/my.cnf, expire_logs_days = 10. 0. But without this addition, as more and more binlog is generated, the disk is eaten up a lot. You can delete binlog files directly, but you can delete them more securely through the tools provided by mysql. Because purge will update the entries in mysql-bin.index, and if you delete it directly, the mysql-bin.index file will not be updated. The purpose of mysql-bin.index is to speed up the search for binlog files.

Let's help first.

:

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 are removed from the list recorded

In the log index file, so that the given log becomes the first.

This statement has 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 purl 46purl 26'

Both methods are available. The first is deleted to a certain file, and the second is deleted to a certain date.

For example, if we delete the log before 2017-05-31, we can do this.

Mysql > PURGE MASTER LOGS BEFORE '2017-05-31 0000 purl 0000'

two。 Set up expire_logs_days

# vim / etc/my.cnf / / modify the number of days for expire_logs_days,x to be deleted automatically. Generally, set x to a short point, such as 10

Expire_logs_days = the number of days that the x / / binary log is automatically deleted. The default value is 0, which means "no automatic deletion"

This method requires a restart of mysql, with an English description of expire_logs_days in the appendix

Of course, you can not restart mysql, turn on mysql master and slave, and directly set expire_logs_days in mysql.

> show binary logs

> show variables like'% log%'

> set global expire_logs_days = 10

It is important to note that it is best to go to slave to see which binlog file is currently synchronized to, and check it with show slave status. Otherwise, if there are too many deletions on master, the log files will be missing in slave and the data will be inconsistent.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report