52.MySQL Innodb_fast_shutdown参数

2022/2/13 19:17:59

本文主要是介绍52.MySQL Innodb_fast_shutdown参数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.前言

  上周在公司主要做了从mysql5.7.21迁移到mysql8.0.25的版本升级迁移,其中在迁移文档中就有这个参数

2.参数介绍

  这里就直接看官方文档上面的介绍说

  

  从这里看出该系统变量有三个可选值,其中1是默认值,然后再来看看它的解释:

The InnoDB shutdown mode. If the value is 0, InnoDB does a slow shutdown, a full purge and a change buffer merge before shutting down. If the value is 1 (the default), InnoDB skips these operations at shutdown, a process known as a fast shutdown. If the value is 2, InnoDB flushes its logs and shuts down cold, as if MySQL had crashed; no committed transactions are lost, but the crash recovery operation makes the next startup take longer.

The slow shutdown can take minutes, or even hours in extreme cases where substantial amounts of data are still buffered. Use the slow shutdown technique before upgrading or downgrading between MySQL major releases, so that all data files are fully prepared in case the upgrade process updates the file format.

Use innodb_fast_shutdown=2 in emergency or troubleshooting situations, to get the absolute fastest shutdown if data is at risk of corruption.

    如果该值是0的话,innodb会做一个慢的关闭过程(为什么慢呢?) --->这是因为在关闭innodb之前首先会做一个完全清除和更改缓冲区合并操作(这句话等会再解释)

    如果该值是1的话,innodb会在关闭之前会跳过这些操作进行关闭,因为这种关闭过程也可以被称为快速关闭。

  如果该值是2的话,innodb会刷新它的日志(这里的日志指的是重做日志redo log)并且进行一个冷关闭(这里我不也不知道什么是冷关闭),就好像mysql发生宕机了一样(就会导致没有提交的事务会丢失),但是在恢复启动的时候它可能需要比较的长的时间。

    在有大量的缓冲数据的时候,使用慢关闭可能需要几分钟甚至几小时。一般使用慢关闭技术会在升级或者降级mysql主流版本的时候使用以便在升级过程更新文件格式时做好所有数据文件的准备

    在紧急情况或故障排除情况下使用 innodb_fast_shutdown=2,以便在数据存在损坏风险时获得绝对最快的关闭速度。

 3.补充

  这里需要补充一些知识,因为只是看上面的官方文档解释可能有点不全面(以下来自于互联网)

  • 0表示在innodb关闭的时候,需要purge all,merge insert buffer,flush dirty pages. 这是一种最慢的关闭方式,但是restart的时候也是最快的
  • 1表示在innodb关闭的时候,它不需要purge all,merge insert buffer,只需要flush dirty page,在缓冲池中的一些数据脏页会刷新到磁盘
  • 2表示在innodb关闭的时候,它不需要purge all,merge insert buffer,也不进行flush dirty page,只将log buffer 里面的日志刷新到日志文件log files,mysql下次启动时,会执行恢复操作   

   如果在上次关闭innodb的时候是在innodb_fast_shutdown=2或是mysql crash这种情况,那么它会利用redo log 重做那些已经提交了的事务

     接下来的操作过程是:

  1. Rollback uncompleted transitions 取消那些没有提交的事务
  2. Purge all 清除无用的undo页
  3. Merge insert buffer 合并插入缓冲

       

 



这篇关于52.MySQL Innodb_fast_shutdown参数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程