(1)提高數據庫插入性能中心思想:盡量將數據一次性寫入到Data File和減少數據庫的checkpoint 操作。這次修改了下面四個配置項:
1)將 innodb_flush_log_at_trx_commit 配置設定為0;按過往經驗設定為0,插入速度會有很大提高。
0: Write the log buffer to the log file and flush the log file every second, but do nothing at transaction commit.
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
2:the log buffer is written out to the file at each commit, but the flush to disk operation is not performed on it
2)將 innodb_autoextend_increment 配置由於默認8M 調整到 128M
此配置項作用主要是當tablespace 空間已經滿了后,需要MySQL系統需要自動擴展多少空間,每次tablespace 擴展都會讓各個SQL 處於等待狀態。增加自動擴展Size可以減少tablespace自動擴展次數。
3)將 innodb_log_buffer_size 配置由於默認1M 調整到 16M
此配置項作用設定innodb 數據庫引擎寫日志緩存區;將此緩存段增大可以減少數據庫寫數據文件次數。
4)將 innodb_log_file_size 配置由於默認 8M 調整到 128M
此配置項作用設定innodb 數據庫引擎UNDO日志的大小;從而減少數據庫checkpoint操作。
經過以上調整,系統插入速度由於原來10分鍾幾萬條提升至1秒1W左右;注:以上參數調整,需要根據不同機器來進行實際調整。特別是 innodb_flush_log_at_trx_commit、innodb_log_buffer_size和 innodb_log_file_size 需要謹慎調整;因為涉及MySQL本身的容災處理。
(2)提升數據庫讀取速度,重數據庫層面上讀取速度提升主要由於幾點:簡化SQL、加索引和分區; 經過檢查程序SQL已經是最簡單,查詢條件上已經增加索引。我們只能用武器:表分區。
-----------------------------------mysql提高insert into 插入速度的3種方法---------------------------------------
當mysql大批量插入數據的時候就會變的非常慢, mysql提高insert into 插入速度的方法有三種:
第一種插入提速方法:
如果數據庫中的數據已經很多(幾百萬條), 那么可以 加大mysql配置中的 bulk_insert_buffer_size,這個參數默認為8M
- bulk_insert_buffer_size=100M
第二種mysql插入提速方法:
改寫所有 insert into 語句為 insert delayed into
這個insert delayed不同之處在於:立即返回結果,后台進行處理插入。
第三個方法: 一次插入多條數據:
insert中插入多條數據,舉例:
insert into table values('11','11'),('22','22'),('33','33')...;