innodb數(shù)據(jù)目錄下默認會有2個名為ib_logfile0和ib_logfile1的重做日志文件,mysql寫重做日志的過程是,事務(wù)進行的過程中,master thread主線程不斷的將事務(wù)中的條目,插入到重做日志緩沖,然后同步到磁盤的重做日志文件(ib_logfile),先寫日志文件1(ib_logfile0),寫滿了,再切換至日志文件2(ib_logfile1),當日志文件2被寫滿了,再切換到日志文件1(ib_logfile0);
問題:既然磁盤上的日志文件1和2已經(jīng)寫滿了,為什么還會再重新切換到日志1再寫入呢?滿了還怎么寫入?
認證高級PHP講師
The ib_logfile of innodb is a fixed-length file, which can be set through innodb_log_file_size = 64M
in my.cnf. mysql will write data sequentially in the pre-allocated space. Until it can no longer be written, it will switch to the next file and continue writing, just like using a circular array in memory. Generally, this kind of log has no long-term value, so this strategy saves disk space and can avoid disk fragmentation, additional IO and other problems caused by the increase in file size.