当前位置: 代码迷 >> SQL >> MY SQL insert 速渡过慢
  详细解决方案

MY SQL insert 速渡过慢

热度:126   发布时间:2016-05-05 14:43:03.0
MY SQL insert 速度过慢
最近在用MySQL做存储,测试中发现插入数据太慢了,插入速度只有20-30 条/秒,后来查资料后,将MySQL的1个参数:innodb_flush_log_at_trx_commit,1改为了0(修改方法,可以直接修改my.ini(windows)/my.cnf(linux)中的对应参数,似乎用命令直接设置没有效果),插入速度就提升到了3000+每S,MySQL的文档中,对这个参数的描述如下:
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.

这样,如果transaction commit的频率非常高,1秒钟内会进行很多次的话,可以考虑将其设置为0,但这样就要承担数据库Crash后,1秒内未存储到数据库数据丢失可能的风险

  相关解决方案