删除旋转的 MySQL 二进制日志是否安全?
我有一个启用了二进制日志记录的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以删除旧的二进制日志。与其直接删除它们,不如使用 MySQL 语句 PURGE BINARY LOGS 更安全,它还会更新您的 mybinlog.index 文件。此文件存储已用于二进制日志记录的文件名,请参阅
http://dev.mysql.com/doc/refman/5.0/en/purge-binary-logs.html
此外,您可以将 MySQL 服务器配置为自动删除旧的二进制日志。将服务器配置中的变量
max_binlog_size
和expire_logs_days
设置为适当的值。ibdata
和ib_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 yourmybinlog.index
file. This file stores which filenames have been used for binary logging, seehttp://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
andexpire_logs_days
in your server configuration to appropriate values.The
ibdata
andib_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
三天前删除所有 bin 文件!
或者
DELETE ALL bin files before 3 DAYS!
or
我终于在MySQL网站上找到了答案。如果有人需要此信息:
这意味着我应该手动编辑 .index 文件,一切都会好起来的。有趣的是 .index 文件是一个常规文本文件。直到现在我才注意到这一点。
I finally found the answer on MySQL website. In case somebody needs this information:
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.
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.