删除旋转的 MySQL 二进制日志是否安全?

发布于 2024-09-04 12:03:50 字数 902 浏览 9 评论 0原文

我有一个启用了二进制日志记录的 MySQL 服务器。一天一次日志文件被“轮换”,即MySQL似乎停止写入它并创建新的日志文件。例如,我目前在 /var/lib/mysql 中有这些文件,

-rw-rw---- 1 mysql mysql 10485760 Jun  7 09:26 ibdata1
-rw-rw---- 1 mysql mysql  5242880 Jun  7 09:26 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 Jun  2 15:20 ib_logfile1
-rw-rw---- 1 mysql mysql  1916844 Jun  6 09:20 mybinlog.000004
-rw-rw---- 1 mysql mysql 61112500 Jun  7 09:26 mybinlog.000005
-rw-rw---- 1 mysql mysql 15609789 Jun  7 13:57 mybinlog.000006
-rw-rw---- 1 mysql mysql       54 Jun  7 09:26 mybinlog.index

并且 mybinlog.000006 正在增长。

我可以简单地获取 mybinlog.000004 和 mybinlog.000005,将它们压缩并传输到另一台服务器,还是我之前需要做其他事情?

mybinlog.index 中存储了哪些信息?仅有关最新二进制日志的信息?

更新:我知道我可以使用 PURGE BINARY LOGS 删除日志,这会更新 mybinlog.index 文件。但是,我需要在删除日志之前将日志传输到另一台计算机(我测试备份在另一台计算机上是否有效)。为了减少传输大小,我希望对文件进行 bzip2。如果日志文件不再“存在”,PURGE BINARY LOGS 会做什么?

I have a MySQL server with binary logging active. Once a day logs file is "rotated", i.e. MySQL seems to stop writing to it and creates and new log file. For example, I currently have these files in /var/lib/mysql

-rw-rw---- 1 mysql mysql 10485760 Jun  7 09:26 ibdata1
-rw-rw---- 1 mysql mysql  5242880 Jun  7 09:26 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 Jun  2 15:20 ib_logfile1
-rw-rw---- 1 mysql mysql  1916844 Jun  6 09:20 mybinlog.000004
-rw-rw---- 1 mysql mysql 61112500 Jun  7 09:26 mybinlog.000005
-rw-rw---- 1 mysql mysql 15609789 Jun  7 13:57 mybinlog.000006
-rw-rw---- 1 mysql mysql       54 Jun  7 09:26 mybinlog.index

and mybinlog.000006 is growing.

Can I simply take mybinlog.000004 and mybinlog.000005, zip them up and transfer to another server, or I need to do something else before?

What info is stored in mybinlog.index? Only the info about the latest binary log?

UPDATE: I understand I can delete the logs with PURGE BINARY LOGS which updates mybinlog.index file. However, I need to transfer logs to another computer before deleting them (I test if backup is valid on another machine). To reduce the transfer size, I wish to bzip2 the files. What will PURGE BINARY LOGS do if log files are not "there" anymore?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

可遇━不可求 2024-09-11 12:03:50

您可以删除旧的二进制日志。与其直接删除它们,不如使用 MySQL 语句 PURGE BINARY LOGS 更安全,它还会更新您的 mybinlog.index 文件。此文件存储已用于二进制日志记录的文件名,请参阅

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

此外,您可以将 MySQL 服务器配置为自动删除旧的二进制日志。将服务器配置中的变量 max_binlog_sizeexpire_logs_days 设置为适当的值。

ibdataib_logfile 文件与二进制日志记录无关。它们由 innodb 存储引擎使用。不要误认为它们似乎不会增长:如果您的服务器上有 innodb 表,这些文件很重要,删除它们可能会导致数据丢失。您可以在文档中阅读有关 InnoDB 的更多信息:

http://dev .mysql.com/doc/refman/5.0/en/innodb-configuration.html

You can delete old binary logs. Instead of deleting them directly, it is safer to use the MySQL-statement PURGE BINARY LOGS which also updates your mybinlog.index file. This file stores which filenames have been used for binary logging, see

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

Further, you can configure your MySQL-Server to delete old binary logs automatically. Set the variables max_binlog_size and expire_logs_days in your server configuration to appropriate values.

The ibdata and ib_logfile files have nothing to do with binary logging. They are used by the innodb storage engine. Do not be mistaken by the fact that they do not seem to grow: If you have innodb-tables on your server, these files are important and deleting them may result in loss of data. You can read more about InnoDB in the docs:

http://dev.mysql.com/doc/refman/5.0/en/innodb-configuration.html

还给你自由 2024-09-11 12:03:50
mysql> PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY; 

三天前删除所有 bin 文件!

或者

PURGE MASTER LOGS BEFORE '2010-10-08 00:00:00';
mysql> PURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY; 

DELETE ALL bin files before 3 DAYS!

or

PURGE MASTER LOGS BEFORE '2010-10-08 00:00:00';
壹場煙雨 2024-09-11 12:03:50

我终于在MySQL网站上找到了答案。如果有人需要此信息:

在 MySQL 5.0.60 之前,当 .index 文件中列出的二进制日志文件已从系统中删除时,PURGE BINARY LOGS TO 和 PURGE BINARY LOGS BEFORE 的行为方式不同(并且两者的行为都不正确)其他一些方法(例如在 Linux 上使用 rm)。从 MySQL 5.0.60 开始,在这种情况下,该语句的两种变体都会失败并出现错误。 (Bug#18199、Bug#18453)要处理此类错误,请手动编辑 .index 文件(这是一个简单的文本文件)以确保它仅列出实际存在的二进制日志文件,然后再次运行 PURGE BINARY LOGS失败的声明。

这意味着我应该手动编辑 .index 文件,一切都会好起来的。有趣的是 .index 文件是一个常规文本文件。直到现在我才注意到这一点。

I finally found the answer on MySQL website. In case somebody needs this information:

Prior to MySQL 5.0.60, PURGE BINARY LOGS TO and PURGE BINARY LOGS BEFORE did not behave in the same way (and neither one behaved correctly) when binary log files listed in the .index file had been removed from the system by some other means (such as using rm on Linux). Beginning with MySQL 5.0.60, both variants of the statement fail with an error in such cases. (Bug#18199, Bug#18453) To handle such errors, edit the .index file (which is a simple text file) manually to ensure that it lists only the binary log files that are actually present, then run again the PURGE BINARY LOGS statement that failed.

This means I should edit .index file manually and everything will be fine. What's interesting is that .index file is a regular textual file. I didn't even notice that until now.

那片花海 2024-09-11 12:03:50

mysql-bin.index 通常包含所有 .bin 文件。如果您删除了一些文件,请编辑 .index 以反映所有可用文件。如果您已删除所有 .bin 文件,请删除空的 .index 文件。这将解决你的问题。

mysql-bin.index usually carry all the .bin files. If u have removed some files pls edit the .index to reflect what are all files available. If u have removed all .bin files remove empty the .index file. This will solve u r problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文