mysql数据库插入速度和读取速度的调优

本文分享了在面临短时间内大量数据插入需求时,如何通过调整MySQL配置(如innodb_flush_log_at_trx_commit、innodb_autoextend_increment、innodb_log_buffer_size和innodb_log_file_size)来提升插入速度,以及通过表分区、简化SQL和加索引来改善读取性能的过程。调整后,插入速度从每分钟千余条提升至每秒万余条,但读取速度提升不明显,仍需进一步优化。
摘要由CSDN通过智能技术生成

由于项目变态需求;需要在一个比较短时间段急剧增加数据库记录(两三天内,由于0增加至4亿)。在整个过程调优过程非常艰辛


(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 配置由

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值