一、双1参数
1、innodb_flush_log_at_trx_commit
innodb_flush_log_at_trx_commit这个参数控制MySQL在事务提交时将内存中的Redo log file从Redo log buffer刷新到磁盘(Redo log file)的方式。
value: 0 1 2
1)0
每秒钟将内存中Redo log File从Redo Log Buffer刷新到OS Buffer并调用fsync()将OS Buffer刷新到磁盘(数据库宕机时,可能会有数据丢失)
2)1
默认为1,表示每次事务提交时会将Redo Log File从Redo Log Buffer中刷新到OS Buffer,并且会调用fsync()将OS Buffer刷新到磁盘(数据库宕机时,不会有数据丢失)
3)2
每次事务提交时会将内存中Redo Log File从Redo Log Buffer中刷新到OS Buffer,每秒钟调用fsync()将OS Buffer刷新到磁盘(数据库宕机时,可能会有数据丢失)
2、sync_binlog
sync_binlog参数控制将内存中binlog从binlog buffer中刷新到磁盘的方式
value : 0 1 N
1)0
由OS决定什么时候调用fsync()来将内存中binlog file从binlog buffer刷新到磁盘(binlog file).
2)1
每次事务提交时,将内存中binlog file从binlog buffer中刷新到磁盘(binlog file).
3)N
每N次事务提交时,将内存中的binlog file从binlog buffer中刷新到磁盘(binlog file).
注:binlog buffer满的时候会自动调用fsync()同步binlog buffer到磁盘(binlog file).
二、两阶段提交
MySQL采用两阶段提交的方式来保证有数据库变更的时候写入Redo Log File和Binlog File数据的一致性.
1、Redo Write
2、Redo prepare(fsync())
3、Binlog Write
4、Redo Commit