大家在使用innodb数据库的时候,会发现有这么一个现象,当我们需要关闭或者重新启动mysql服务的时候,会需要相当一段长的时间,如果是数据库进程异常关闭,打开数据库又会花很长的时间来作恢复。
开始还以为是数据库太大了引起的,后来看到一篇文章讲的是 “innodb_max_dirty_pages_pct与检查点的关系” ,才明白其中的道理。通常的原因是来自 buffer pool 的脏页数据交换,mysql会通知OS,把一些脏页交换出去,而交换是在内存中进行修改,而不是在硬盘上。
如果你需要快速关闭 innodb 数据库,那么有一个办法,如下:
1,设置全局变量,设置 innodb_max_dirty_pages_pct 参数的值。
mysql> set global innodb_max_dirty_pages_pct = 0;
2,执行如下命令,查看被修改的数据页面。
/usr/local/mysql/bin/mysqladmin -uroot -p ext -i10 | grep dirty
Enter password:
| Innodb_buffer_pool_pages_dirty | 4530 |
| Innodb_buffer_pool_pages_dirty | 4576 |
| Innodb_buffer_pool_pages_dirty | 4475 |
| Innodb_buffer_pool_pages_dirty | 4496 |
| Innodb_buffer_pool_pages_dirty | 4411 |
当这个参数变为 0,或者接近 0(如果你的服务器在使用,是不会变成 0 的)。
此时,这个数值相当的低时,你就可以重新启动你的数据库服务,这个时候,你会发现速度相当的快。
注意:
这个数值和 innodb buffer 有很大的关系,一般不建议更改这个数值,除非你的 innodb buffer 很大。我这里有3台数据库服务器,一个设置了3G的 innodb buffer 脏页数据在1000左右,其他的是1G的 innodb buffer 脏页在4000左右,,看来还是 innodb buffer 越大越好呀!
也许你会说可以通过 innodb_fast_shutdown 这个选项来调整关闭速度,系统默认为 1,但是如果你将此项的值修改为 0 或者 2,,这样的mysql就比较危险。
官方描述如下:
The InnoDB shutdown mode. By default, the value is 1, which causes a “fast” shutdown (the normal type of shutdown).
If the value is 0, InnoDB does a full purge and an insert buffer merge before a shutdown. These operations can take minutes, or even hours in extreme cases.
If the value is 1, InnoDB skips these operations at shutdown.
If the value is 2, InnoDB will just flush its logs and then shut down cold, as if MySQL had crashed; no committed transaction will be lost, but crash recovery will be done at the next startup. A value of 2 cannot be used on NetWare.
详细解决方案
如何减少 innodb 数据库关闭的时间?
热度:99 发布时间:2024-01-29 11:14:22.0
相关解决方案
- MySQL: InnoDB 还是 MyISAM?
- mysql数据库报错:InnoDB: Operating system error number 13 in a file operation
- mysql innodb redo log
- [DB] InnoDB 作为默认存储引擎(从mysql-5.5.5开始)
- [DB] MyISAM InnoDB 发音(怎么读,读什么)
- 浅入浅出-MySQL 和 InnoDB
- innodb 索引系列(2)为什么mysql 建议使用自增主键
- mysql 启动异常处理:[ERROR] InnoDB: Operating system error number 13 in a file operation.
- mysql innodb 表行大小限制(Row Size Limit)ERROR 1118 (42000): Row size too large ( 8126).
- mysql innodb ibdata 数据文件误删除恢复过程
- Mysql启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 by
- mysql innodb,MyISAM 两种引擎测试
- mysql 中 myisam innodb 的区别有哪些
- InnoDB 存储引擎(7)——日志文件
- InnoDB 存储引擎(6)——异步IO
- InnoDB 存储引擎(5)——自适应哈希索引
- mysql数据库的引擎 MyIASM/Innodb 详解
- MySQL的存储引擎-Innodb MyISAM差异
- 如何快速关闭mysql/innodb?
- MySQL事务,读写锁,行表锁及存储引擎 MyISAM 与 InnoDB
- 详解“InnoDB”和“MyISAM”的不同之处
- Hibernate 自动建表 type=InnoDB 错误
- MySQL 'type=InnoDB' 错误
- 如何减少 innodb 数据库关闭的时间?