简体   繁体   English

如何刷新二进制日志

[英]How to flush binary logs

I read a comment on another post that InnoDB can be optimized for speed by not flushing binary logs on every commit. 我在另一篇文章中读到一篇评论,指出可以通过不在每次提交时刷新二进制日志来优化InnoDB的速度。

This is the first time I hear about this, so what are these binary logs and what's this flushing all about? 这是我第一次听说此消息,那么这些二进制日志是什么?刷新的内容是什么? Why should I do it (and when not to do it) and how? 我为什么要这样做(什么时候不这样做)以及如何做?

MySQL's binary log acts as the database equivalent the journal in a journaling file system. MySQL的二进制日志充当相当于日志文件系统中日志的数据库。 Every query gets logged in it, so that if the DB crashes at some point, you can "replay" the binary log and rebuild the DB with minimal pain. 每个查询都会记录在其中,因此,如果数据库在某个时刻崩溃,则可以“重播”二进制日志并以最小的代价重建数据库。 It's also used in replication. 它也用于复制。

More details here: http://dev.mysql.com/doc/refman/5.1/en/binary-log.html 此处有更多详细信息: http : //dev.mysql.com/doc/refman/5.1/en/binary-log.html

The binary logs are used in crash recovery and replication. 二进制日志用于崩溃恢复和复制。 Assuming they are enabled, the two main applicable settings regarding flushing are: 假设已启用它们,则有关冲洗的两个主要适用设置为:

  • innodb_flush_log_at_trx_commit=2 innodb_flush_log_at_trx_commit = 2
  • sync_binlog=0 sync_binlog = 0

Those settings favor speed over "guaranteed" reliability because they allow the OS to delay in flushing the buffers to disk. 这些设置优先于速度而不是“保证的”可靠性,因为它们允许操作系统延迟将缓冲区刷新到磁盘上。

If you are running on a cheap disk controller (most people are), flushing the logs out on every commit is very slow. 如果您在便宜的磁盘控制器上运行(大多数人都在使用),则每次提交都刷新日志非常慢。 On a site that does a lot of writes, I've seen page execution time drop 10x-100x! 在执行大量写操作的网站上,我看到页面执行时间减少了10x-100x! It's easy to run your own benchmarks and see how it affects you. 运行您自己的基准测试并查看其如何影响您很容易。

To be very clear, if you want maximum recovery benefits, you must set both of those values to 1. As configured above, you may lose a few seconds of data in the case of a system crash. 明确地说,如果要获得最大的恢复收益,则必须将这两个值都设置为1。如上所述,在系统崩溃的情况下,您可能会丢失几秒钟的数据。 For some sites, that is not acceptable. 对于某些网站,这是不可接受的。 For blogs and forums, it probably is a worthwhile trade-off. 对于博客和论坛,这可能是一个值得权衡的问题。

You can read more about the settings here: 您可以在此处阅读有关设置的更多信息:

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

There are many memory related options like 'innodb_buffer_pool_size' to configure as well. 还有许多与内存相关的选项,例如“ innodb_buffer_pool_size”也要配置。 A search on MySQL InnoDB tuning should help out. 有关MySQL InnoDB调优的搜索应该会有所帮助。

InnoDB recovers from crashes by replaying the logs. InnoDB通过重播日志从崩溃中恢复。 And it's also used for replicating master server to slave ones. 而且它还用于将主服务器复制到从服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM