innodb_flush_log_at_trx_commit
innodb_buffer_pool_size
如 果用Innodb,那么這是一個(gè)重要變量。相對(duì)于MyISAM來說,Innodb對(duì)于buffer size更敏感。MySIAM可能對(duì)于大數(shù)據(jù)量使用默認(rèn)的key_buffer_size也還好,但I(xiàn)nnodb在大數(shù)據(jù)量時(shí)用默認(rèn)值就感覺在爬了。 Innodb的緩沖池會(huì)緩存數(shù)據(jù)和索引,所以不需要給系統(tǒng)的緩存留空間,如果只用Innodb,可以把這個(gè)值設(shè)為內(nèi)存的70%-80%。和 key_buffer相同,如果數(shù)據(jù)量比較小也不怎么增加,那么不要把這個(gè)值設(shè)太高也可以提高內(nèi)存的使用率。
innodb_additional_pool_size?
這個(gè)的效果不是很明顯,至少是當(dāng)操作系統(tǒng)能合理分配內(nèi)存時(shí)。但你可能仍需要設(shè)成20M或更多一點(diǎn)以看Innodb會(huì)分配多少內(nèi)存做其他用途。
innodb_log_file_size
對(duì)于寫很多尤其是大數(shù)據(jù)量時(shí)非常重要。要注意,大的文件提供更高的性能,但數(shù)據(jù)庫恢復(fù)時(shí)會(huì)用更多的時(shí)間。我一般用64M-512M,具體取決于服務(wù)器的空間。
innodb_log_buffer_size?
默認(rèn)值對(duì)于多數(shù)中等寫操作和事務(wù)短的運(yùn)用都是可以的。如 果經(jīng)常做更新或者使用了很多blob數(shù)據(jù),應(yīng)該增大這個(gè)值。但太大了也是浪費(fèi)內(nèi)存,因?yàn)?秒鐘總會(huì) flush(這個(gè)詞的中文怎么說呢?)一次,所以不需要設(shè)到超過1秒的需求。8M-16M一般應(yīng)該夠了。小的運(yùn)用可以設(shè)更小一點(diǎn)。
innodb_flush_log_at_trx_commit? (這個(gè)很管用)?
抱怨Innodb比MyISAM慢 100倍?那么你大概是忘了調(diào)整這個(gè)值。默認(rèn)值1的意思是每一次事務(wù)提交或事務(wù)外的指令都需要把日志寫入(flush)硬盤,這是很費(fèi)時(shí)的。特別是使用電 池供電緩存(Battery backed up cache)時(shí)。設(shè)成2對(duì)于很多運(yùn)用,特別是從MyISAM表轉(zhuǎn)過來的是可以的,它的意思是不寫入硬盤而是寫入系統(tǒng)緩存。日志仍然會(huì)每秒flush到硬 盤,所以你一般不會(huì)丟失超過1-2秒的更新。設(shè)成0會(huì)更快一點(diǎn),但安全方面比較差,即使MySQL掛了也可能會(huì)丟失事務(wù)的數(shù)據(jù)。而值2只會(huì)在整個(gè)操作系統(tǒng) 掛了時(shí)才可能丟數(shù)據(jù)。?
innodb_flush_log_at_trx_commit
If the value of?innodb_flush_log_at_trx_commit?is 0, the log buffer is written out to the log file once per second and the flush to disk operation is performed on the log file, but nothing is done at a transaction commit. When the value is 1, the log buffer is written out to the log file at each transaction commit and the flush to disk operation is performed on the log file. When the value is 2, the log buffer is written out to the file at each commit, but the flush to disk operation is not performed on it. However, the flushing on the log file takes place once per second also when the value is 2. Note that the once-per-second flushing is not 100% guaranteed to happen every second, due to process scheduling issues.
The default value of this variable is 1 (prior to MySQL 4.0.13, the default is 0).
A value of 1 is required for ACID compliance. You can achieve better performance by setting the value different from 1, but then you can lose at most one second worth of transactions in a crash. With a value of 0, any?mysqldprocess crash can erase the last second of transactions. With a value of 2, then only an operating system crash or a power outage can erase the last second of transactions. However,?InnoDB's crash recovery is not affected and thus crash recovery does work regardless of the value.
NoteFor the greatest possible durability and consistency in a replication setup using?InnoDB?with transactions, use?innodb_flush_log_at_trx_commit=1,?sync_binlog=1, and?innodb-safe-binlog?in your master server?my.cnf?file.
CautionMany operating systems and some disk hardware fool the flush-to-disk operation. They may tellmysqld?that the flush has taken place, even though it has not. Then the durability of transactions is not guaranteed even with the setting 1, and in the worst case a power outage can even corrupt theInnoDB?database. Using a battery-backed disk cache in the SCSI disk controller or in the disk itself speeds up file flushes, and makes the operation safer. You can also try using the Unix commandhdparm?to disable the caching of disk writes in hardware caches, or use some other command specific to the hardware vendor.
總結(jié)
以上是生活随笔為你收集整理的innodb_flush_log_at_trx_commit的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx和lvs在负载均衡方面的对比
- 下一篇: 由于CRS磁盘dismount造成的CR