MYSQL 优化innodb_flush_log_at_trx_commit
来源:互联网 发布:ubuntu g 编译命名 编辑:程序博客网 时间:2024/05/29 16:30
问题描述:我的Win7上装了一个MYSQL,今天需要向表中插入160多万条数据,SQL文件大概126M,发现速度奇慢。
解决办法:1 找到C:\Program Files\MySQL\MySQL Server 5.5\my.ini;2 令innodb_flush_log_at_trx_commit=0。
为什么这样改?
原文是这样的
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
即如果将参数innodb_flush_log_at_trx_commit设置为1,每当事务提交,InnoDB引擎就会将事务日志写入硬盘,这可以完整保证数据库的ACID特性。
如果您觉得这样的保证没有必要,并且你的事务都是比较小的事务(运行时间比较短、逻辑比较简单),你可以将innodb_flush_log_at_trx_commit设置为0或者是
2,这样可以减少访问磁盘日志的次数。0意味着日志只写入日志文件,日志文件大约每秒钟向磁盘写一次;2意味着日志在每次事务提交的时候写入日志文件,且大约每秒钟日志文件写入一次磁盘。
==============================================================================================================================
上面这个方法貌似可以解决问题,也确实可以,但是隐患很大、影响很大。数据之所以插入慢,是因为MYSQL默认情况下是自动提交的,即没插入一条记录就是一个事务,就要写一次文件,所以很慢。我们可以在一个session中把自动提交设成false(set @@autocommit=0),然后执行所有的(或者分批) insert,然后来一个commit,OK!
- MYSQL 优化innodb_flush_log_at_trx_commit
- mysql 优化之innodb_flush_log_at_trx_commit
- mysql innodb_flush_log_at_trx_commit
- mysql innodb_flush_log_at_trx_commit
- mysql innodb_flush_log_at_trx_commit
- 【MySQL】sync_binlog innodb_flush_log_at_trx_commit 浅析
- MySQL配置项innodb_flush_log_at_trx_commit
- 【MySQL】sync_binlog innodb_flush_log_at_trx_commit 浅析
- 【MySQL】sync_binlog innodb_flush_log_at_trx_commit 浅析
- 10015---MySQL--innodb_flush_log_at_trx_commit参数
- mysql 性能参数 innodb_flush_log_at_trx_commit
- MySQL的innodb_flush_log_at_trx_commit
- 【MySQL】sync_binlog innodb_flush_log_at_trx_commit 浅析
- mysql sync_binlog 和innodb_flush_log_at_trx_commit
- 【MySQL】sync_binlog innodb_flush_log_at_trx_commit 浅析
- MySQL参数:innodb_flush_log_at_trx_commit 和 sync_binlog
- 有关mysql的innodb_flush_log_at_trx_commit参数
- innodb_flush_log_at_trx_commit
- linux查看内存
- How to host WordPress for free on AWS
- 获取Windows网络连接状况
- php mysql 数据库链接与操作
- 多线程与多进程
- MYSQL 优化innodb_flush_log_at_trx_commit
- 理解 Flex itemRenderer - 第 1 部分: 内联渲染器
- IM开发【1】 - Smack类库详细介绍 - 基于XMPP的即时通讯机制
- slf4j和log4j配置
- 教你如何迅速秒杀掉:99%的海量数据处理面试题
- linux下system函数介绍
- nginx负载均衡器处理session共享的几种方法
- redis-faina:一个Redis的query分析小工具
- MPMoviePlayerViewController实现横屏播放