佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > MySQL刪除和插入數(shù)據(jù)很慢的問(wèn)題解決

MySQL刪除和插入數(shù)據(jù)很慢的問(wèn)題解決

熱門(mén)標(biāo)簽:AI電銷(xiāo) 地方門(mén)戶(hù)網(wǎng)站 呼叫中心市場(chǎng)需求 網(wǎng)站排名優(yōu)化 百度競(jìng)價(jià)排名 鐵路電話系統(tǒng) Linux服務(wù)器 服務(wù)外包

公司開(kāi)發(fā)人員在測(cè)試環(huán)境中執(zhí)行一條 insert 語(yǔ)句時(shí),需要花費(fèi) 10 幾秒才可以執(zhí)行成功。查看測(cè)試環(huán)境數(shù)據(jù)庫(kù)性能、數(shù)據(jù)量、死鎖等信息,均為發(fā)現(xiàn)異常。最后通過(guò)修改日志寫(xiě)入方式解決此問(wèn)題。

1. 修改辦法

修改/etc/my.cnf文件,將 innodb_flush_log_at_trx_commit = 1改為0, 但這樣就要承擔(dān)數(shù)據(jù)庫(kù)Crash后,1秒內(nèi)未存儲(chǔ)到數(shù)據(jù)庫(kù)數(shù)據(jù)丟失可能的風(fēng)險(xiǎn)。MySQL文檔中對(duì)該參數(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ù)說(shuō)明

  • 0:log buffer將每秒一次地寫(xiě)入log file中,并且log file的flush(刷到磁盤(pán))操作同時(shí)進(jìn)行。該模式下在事務(wù)提交的時(shí)候,不會(huì)主動(dòng)觸發(fā)寫(xiě)入磁盤(pán)的操作
  • 1:每次事務(wù)提交時(shí)MySQL都會(huì)把log buffer的數(shù)據(jù)寫(xiě)入log file,并且flush(刷到磁盤(pán))中去,該模式為系統(tǒng)默認(rèn)
  • 2:每次事務(wù)提交時(shí)MySQL都會(huì)把log buffer的數(shù)據(jù)寫(xiě)入log file,但是flush(刷到磁盤(pán))操作并不會(huì)同時(shí)進(jìn)行。該模式下,MySQL會(huì)每秒執(zhí)行一次 flush(刷到磁盤(pán))操作

3. 注意事項(xiàng)

當(dāng)設(shè)置為0時(shí),該模式速度最快,但不太安全,mysqld進(jìn)程的崩潰會(huì)導(dǎo)致上一秒鐘所有事務(wù)數(shù)據(jù)的丟失。

當(dāng)設(shè)置為1時(shí),該模式是最安全的,但也是最慢的一種方式。在mysqld 服務(wù)崩潰或者服務(wù)器主機(jī)crash的情況下,binary log 只有可能丟失最多一個(gè)語(yǔ)句或者一個(gè)事務(wù)。

當(dāng)設(shè)置為2時(shí),該模式速度較快,也比0安全,只有在操作系統(tǒng)崩潰或者系統(tǒng)斷電的情況下,上一秒鐘所有事務(wù)數(shù)據(jù)才可能丟失。

innodb_flush_log_at_trx_commit和sync_binlog 兩個(gè)參數(shù)是控制MySQL 磁盤(pán)寫(xiě)入策略以及數(shù)據(jù)安全性的關(guān)鍵參數(shù),當(dāng)兩個(gè)參數(shù)都設(shè)置為1的時(shí)候?qū)懭胄阅茏畈睿扑]做法是innodb_flush_log_at_trx_commit=2,sync_binlog=500 或1000。

到此這篇關(guān)于MySQL刪除和插入數(shù)據(jù)很慢的問(wèn)題解決的文章就介紹到這了,更多相關(guān)MySQL刪除和插入數(shù)據(jù)很慢內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 詳解Navicat遠(yuǎn)程連接mysql很慢
  • Mysql查詢(xún)很慢卡在sending data的原因及解決思路講解
  • MySQL數(shù)據(jù)庫(kù)遠(yuǎn)程連接很慢的解決方案
  • 解決MySQL Sending data導(dǎo)致查詢(xún)很慢問(wèn)題的方法與思路
  • 解決遠(yuǎn)程連接mysql很慢的方法(mysql_connect 打開(kāi)連接慢)
  • 禁止mysql做域名解析(解決遠(yuǎn)程訪問(wèn)mysql時(shí)很慢)

標(biāo)簽:崇左 湘潭 黃山 蘭州 衡水 湖南 仙桃 銅川

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《MySQL刪除和插入數(shù)據(jù)很慢的問(wèn)題解決》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢(xún)

    • 400-1100-266
    安远县| 汪清县| 虹口区| 茶陵县| 册亨县| 蕲春县| 高州市| 曲阜市| 界首市| 开原市| 抚远县| 措勤县| 栾川县| 萨嘎县| 呼伦贝尔市| 广丰县| 诸城市| 远安县| 乌海市| 安龙县| 克拉玛依市| 鲁山县| 曲水县| 岚皋县| 齐齐哈尔市| 铅山县| 嵊州市| 安徽省| 凤城市| 文安县| 河间市| 富民县| 浑源县| 金塔县| 定日县| 广饶县| 朝阳市| 洛宁县| 凤阳县| 永德县| 镇巴县|