MySQL刪除和插入數(shù)據(jù)很慢的問題解決
公司開發(fā)人員在測試環(huán)境中執(zhí)行一條 insert 語句時,需要花費(fèi) 10 幾秒才可以執(zhí)行成功。查看測試環(huán)境數(shù)據(jù)庫性能、數(shù)據(jù)量、死鎖等信息,均為發(fā)現(xiàn)異常。最后通過修改日志寫入方式解決此問題。
1. 修改辦法
修改/etc/my.cnf文件,將 innodb_flush_log_at_trx_commit = 1改為0, 但這樣就要承擔(dān)數(shù)據(jù)庫Crash后,1秒內(nèi)未存儲到數(shù)據(jù)庫數(shù)據(jù)丟失可能的風(fēng)險。MySQL文檔中對該參數(shù)的描述如下:
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 default), 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.
2. 參數(shù)說明
- 0:log buffer將每秒一次地寫入log file中,并且log file的flush(刷到磁盤)操作同時進(jìn)行。該模式下在事務(wù)提交的時候,不會主動觸發(fā)寫入磁盤的操作
- 1:每次事務(wù)提交時MySQL都會把log buffer的數(shù)據(jù)寫入log file,并且flush(刷到磁盤)中去,該模式為系統(tǒng)默認(rèn)
- 2:每次事務(wù)提交時MySQL都會把log buffer的數(shù)據(jù)寫入log file,但是flush(刷到磁盤)操作并不會同時進(jìn)行。該模式下,MySQL會每秒執(zhí)行一次 flush(刷到磁盤)操作
3. 注意事項(xiàng)
當(dāng)設(shè)置為0時,該模式速度最快,但不太安全,mysqld進(jìn)程的崩潰會導(dǎo)致上一秒鐘所有事務(wù)數(shù)據(jù)的丟失。
當(dāng)設(shè)置為1時,該模式是最安全的,但也是最慢的一種方式。在mysqld 服務(wù)崩潰或者服務(wù)器主機(jī)crash的情況下,binary log 只有可能丟失最多一個語句或者一個事務(wù)。
當(dāng)設(shè)置為2時,該模式速度較快,也比0安全,只有在操作系統(tǒng)崩潰或者系統(tǒng)斷電的情況下,上一秒鐘所有事務(wù)數(shù)據(jù)才可能丟失。
innodb_flush_log_at_trx_commit和sync_binlog 兩個參數(shù)是控制MySQL 磁盤寫入策略以及數(shù)據(jù)安全性的關(guān)鍵參數(shù),當(dāng)兩個參數(shù)都設(shè)置為1的時候?qū)懭胄阅茏畈睿扑]做法是innodb_flush_log_at_trx_commit=2,sync_binlog=500 或1000。
到此這篇關(guān)于MySQL刪除和插入數(shù)據(jù)很慢的問題解決的文章就介紹到這了,更多相關(guān)MySQL刪除和插入數(shù)據(jù)很慢內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mysql四種分區(qū)方式以及組合分區(qū)落地實(shí)現(xiàn)詳解
對用戶來說,分區(qū)表是一個獨(dú)立的邏輯表,但是底層由多個物理子表組成,下面這篇文章主要給大家介紹了關(guān)于Mysql四種分區(qū)方式以及組合分區(qū)落地實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2022-04-04mysql升級到5.7時,wordpress導(dǎo)數(shù)據(jù)報錯1067的問題
小編最近把mysql升級到5.7了,wordpress導(dǎo)數(shù)據(jù)報錯,導(dǎo)入數(shù)據(jù)庫時報1067 – Invalid default value for ‘字段名’的問題,怎么解決這個問題,下面小編把我的解決方案分享到腳本之家平臺供大家參考,希望對大家有所幫助2021-05-05MySQL錯誤ERROR 2002 (HY000): Can''t connect to local MySQL ser
這篇文章主要介紹了MySQL錯誤ERROR 2002 (HY000): Can't connect to local MySQL server through socket,需要的朋友可以參考下2014-10-10mysql 8.0 錯誤The server requested authentication method unkno
在本篇文章里小編給大家整理的是關(guān)于mysql 8.0 錯誤The server requested authentication method unknown to the client解決方法,有此需要的朋友們可以學(xué)習(xí)下。2019-08-08MySQL出現(xiàn)this?is?incompatible?with?sql_mode=only_full_grou
mysql是高版本,當(dāng)執(zhí)行g(shù)roup?by時,select的字段不屬于group?by的字段的話,sql語句就會報錯,下面這篇文章主要給大家介紹了關(guān)于MySQL出現(xiàn)this?is?incompatible?with?sql_mode=only_full_group_by錯誤的解決辦法,需要的朋友可以參考下2023-02-02Oracle10個分區(qū)和Mysql分區(qū)區(qū)別詳解
MySQL分區(qū)常用的是:range、list、hash、key,Oracle10g分區(qū)常用的是:range(范圍分區(qū))、list(列表分區(qū))、hash(哈希分區(qū))、range-hash(范圍—哈希分區(qū))、range-list(列表—復(fù)合分區(qū))。下面通過本文詳細(xì)給大家介紹Oracle10個分區(qū)和Mysql分區(qū)區(qū)別,一起看看2017-02-02