MySQL参数: innodb_flush_log_at_trx_commit和sync_binlog

innodb_flush_log_at_trx_commitsync_binlog是MySQL控制磁盘写入策略的重要参数.

  • innodb_flush_log_at_trx_commit

    1. innodb_flush_log_at_trx_commit=0时, log buffer将每秒一次地写入log file, 并且log file的flush(刷新到disk)操作同时进行. 此时, 事务提交是不会主动触发写入磁盘的操作.

    2. innodb_flush_log_at_trx_commit=1时(默认), 每次事务提交时, MySQL会把log buffer的数据写入log file, 并且将log file flush(刷新到disk)中去.

    3. innodb_flush_log_at_trx_commit=2时, 每次事务提交时, MySQL会把log buffer的数据写入log file, 但不会主动触发flush(刷新到disk)操作同时进行. 然而, MySQL会每秒执行一次flush(刷新到disk)操作.

      然而, 每秒flush并不能确保100%每秒发生, 因为os调度问题.

    默认的1可以获得更好地数据安全, 但性能会打折扣. 不过非1时, 在遇到crash可能会丢失1秒的事务; 设置为0时, 任何mysqld进程crash会丢失上1秒的事务; 设置为2时, 任何os crash或者机器掉电会丢失上1秒的事务; InnoDB的crash recovery运行时会忽略这些数据.

  • sync_binlog

      ![](http://images2015.cnblogs.com/blog/748358/201603/748358-20160327131735761-1330837796.png)
    1. sync_binlog=0时(默认), 如os刷新其他文件的机制一样, MySQL不会刷新log buffer到disk中去, 而是依赖os机制刷新log buffer数据到binary log中.

    2. sync_binlog=1时, MySQL在写1次二进制日志binary log时, 会使用fdatasync()函数将二进制binary log同步到disk中去.(安全性最高的配置)

    3. sync_binlog=N(N>1)时, MySQL在写N次二进制日志binary log时, 会使用fdatasync()函数将二进制binary log同步到disk中去.


当两个参数设置为双1的时候, 写入性能最差. 当sync_binlog=N(N>1) && innodb_flush_log_at_trx_commit=2, MySQL的写操作才能达到最高性能.


ref:

https://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html

[MySQL] 参数: innodb_flush_log_at_trx_commit和sync_binlog的更多相关文章

  1. MySQL参数: innodb_flush_log_at_trx_commit和sync_binlog

    innodb_flush_log_at_trx_commit 当innodb_flush_log_at_trx_commit=0时, log buffer将每秒一次地写入log file, 并且log ...

  2. mysql 开发进阶篇系列 19 MySQL Server(innodb_flush_log_at_trx_commit与sync_binlog)

    一. innodb_flush_log_at_trx_commit 这个参数名称有个log,一看就是与日志有关.是指:用来控制缓冲区(log buffer)中的数据写入到日志文件(log file), ...

  3. mysql参数innodb_flush_log_at_trx_commit

    查看mysql数据库innodb_flush_log_at_trx_commit : mysql> SHOW GLOBAL VARIABLES LIKE 'innodb_flush_log%'; ...

  4. MySQL 重要参数 innodb_flush_log_at_trx_commit 和 sync_binlog

    innodb_flush_log_at_trx_commit 主要控制了innodb将log buffer中的数据写入日志文件并flush磁盘的时间点,取值分别为0.1.2三个.该参数控制重做日志写入 ...

  5. MySQL参数:innodb_flush_log_at_trx_commit 和 sync_binlog

    innodb_flush_log_at_trx_commit 和 sync_binlog 是 MySQL 的两个配置参数,前者是 InnoDB 引擎特有的.之所以把这两个参数放在一起讨论,是因为在实际 ...

  6. 有关mysql的innodb_flush_log_at_trx_commit参数

    一.参数解释 0:log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下在事务提交的时候,不会主动触发写入磁盘的操作. 1:每次事务 ...

  7. 有关mysql的innodb_flush_log_at_trx_commit参数【转】

    一.参数解释 0:log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下在事务提交的时候,不会主动触发写入磁盘的操作. 1:每次事务 ...

  8. innodb_flush_log_at_trx_commit和sync_binlog参数详解

    innodb_flush_log_at_trx_commit和sync_binlog参数详解         标签:                             innodb_flush_ ...

  9. innodb_flush_log_at_trx_commit 和 sync_binlog 参数详 解

    "innodb_flush_log_at_trx_commit"和"sync_binlog"两个参数是控制 MySQL 磁盘写入策略以及数据安全性的关键参数.当 ...

随机推荐

  1. 十三、MySQL之IDE工具介绍及数据备份

    一.IDE工具介绍 生产环境还是推荐使用mysql命令行,但为了方便我们测试,可以使用IDE工具 下载链接:https://pan.baidu.com/s/1bpo5mqj 二.MySQL数据备份 # ...

  2. startActivityForResult 请求码不正确

    今天遇到一个坑,就是 startActivityForResult 接收不到正确的请求码. 比如,我startActivityForResult的时候,设置的请求码是4,但是接收到的时候是100032 ...

  3. 《Cracking the Coding Interview》——第9章:递归和动态规划——题目7

    2014-03-20 03:35 题目:实现画图的Flood Fill操作. 解法:DFS和BFS皆可,但BFS使用的队列在时间复杂度上常数项比较大,速度略慢,所以我选了DFS.当然,如果图很大的话D ...

  4. 风格指南--C++

    0.避免多重包含是学编程时基本的要求; 1. 前置声明是为了降低编译依赖,防止修改一个头文件引发多米诺效应; 2. 内联函数的合理使用可提高代码执行效率; 3. ‐inl.h 可提高代码可读性 (一般 ...

  5. 关于mysqldump备份非事务表的注意事项

      Preface       We're used to get a logical backup set(whole instance) by simply specifying "-- ...

  6. windows下vim高亮systemverilog

    主要解决window环境下,vim高亮systemverilog的方法. 第一步:准备材料下载地址:https://files.cnblogs.com/files/aslmer/verilog_sys ...

  7. Day2 Activity生命周期/启动模式/最佳实践

    Android是使用任务(Task)来管理活动的,这个栈被称作返回栈(Back Stack). Activity类中定义了7个回调方法: onCreate().在活动第一次被创建时调用,应该在这个方法 ...

  8. 【现代程序设计】homework-02

    迟交了这么久,一定是0分了.可是我再怎么挣扎,还是不会.交了一维和二维的,这里说说思路吧.. 对于二维的情况,主要的思路就是将二维数组求矩形最大子数组的情况转化为一维的情况.因为所求的是矩形,我们就可 ...

  9. [转] Linux命令行编辑常用键

    ctrl + a 将光标移动到命令行开头相当于VIM里shift+^ ctrl + e 将光标移动到命令行结尾处相当于VIM里shift+$ ctrl + 方向键左键 光标移动到前一个单词开头 ctr ...

  10. LeetCode(一)

    Q&A ONE Given an array of integers, return indices of the two numbers such that they add up to a ...