当前位置:Gxlcms > 数据库问题 > 【案例】利用innodb_force_recovery 解决MySQL服务器crash无法重启问题

【案例】利用innodb_force_recovery 解决MySQL服务器crash无法重启问题

时间:2021-07-01 10:21:17 帮助过:14人阅读


  a 当设置参数值大于0后,可以对表进行select,create,drop操作,但insert,update或者delete这类操作是不允许的。
  b 当innodb_purge_threads 和 innodb_force_recovery一起设置会出现一种loop现象:   

  1. 150125 17:07:42 InnoDB: Waiting for the background threads to start
  2. 150125 17:07:43 InnoDB: Waiting for the background threads to start
  3. 150125 17:07:44 InnoDB: Waiting for the background threads to start
  4. 150125 17:07:45 InnoDB: Waiting for the background threads to start
  5. 150125 17:07:46 InnoDB: Waiting for the background threads to start
  6. 150125 17:07:47 InnoDB: Waiting for the background threads to start

在my.cnf中修改以下两个参数
innodb_force_recovery=6
innodb_purge_thread=0

重启MySQL 

  1. 150125 17:10:47 [Note] Crash recovery finished.
  2. 150125 17:10:47 [Note] Server socket created on IP: ‘0.0.0.0‘.
  3. 150125 17:10:47 [Note] Event Scheduler: Loaded 0 events
  4. 150125 17:10:47 [Note] /vdata/webserver/mysql/bin/mysqld: ready for connections.
  5. Version: ‘5.5.37-MariaDB-log‘ socket: ‘/tmp/mysql.sock‘ port: 3306 Source distribution

立即对数据库做逻辑导出 ,完成之后将innodb_force_recovery设置为0 ,innodb_purge_thread=1 ,然后重建数据库 。
另外 MySQL 版本 5.5以及之前 ,当innodb_purge_threads =1,innodb_force_recovery >1 的情况会出现上文提到的循环报warning 问题(=1 没有问题),
原因:
MySQL 的源代码中显示  当innodb_purge_threads 和 innodb_force_recovery一起设置会出现loop循环

  1. while (srv_shutdown_state == SRV_SHUTDOWN_NONE) {
  2.       if (srv_thread_has_reserved_slot(SRV_MASTER) == ULINT_UNDEFINED
  3.           || (srv_n_purge_threads == 1
  4.           && srv_thread_has_reserved_slot(SRV_WORKER)
  5.           == ULINT_UNDEFINED)) {
  6.           ut_print_timestamp(stderr);
  7.           fprintf(stderr, " InnoDB: Waiting for the background threads to start\n");
  8.           os_thread_sleep(1000000);
  9.       } else {
  10.           break;
  11.       }
  12.   }

所以当需要设置innodb_force_recovery>1的时候需要关闭 innodb_purge_threads,设置为0(默认)。

四 小结 
   MySQL crash 或者 MySQL 数据库服务器 crash 会导致各种各样的问题 ,比如主备之间的error 1594 (5.6 版本开启crash-safe ,会最大程度上避免 error 1594的问题,以后会写5.6新特性介绍该功能 ),error 1236, 日志损坏数据文件损坏 ,等等,本案例只是其中的一种,细心从日志中找的相关错误提示,逐步解决即可。

【案例】利用innodb_force_recovery 解决MySQL服务器crash无法重启问题

标签:rds   double   nec   records   缓冲   无法   possible   base   执行   

人气教程排行