解决数据库Operation not allowed when innodb_forced_recovery > 0

请修改my.cnf

innodb_force_recovery = 1

修改为

innodb_force_recovery = 0

在关闭时,参数innodb_fast_shutdown影响着表的存储引擎为InnoDB的行为。

该参数取值为0、1、2

0 代表党MySql关闭时,InnoDB需要完成所有的full purge 和 merge insert buffer操作,这会需要一些时间。1 代表不需要完成上述的full purge ,merge insert buffer操作,但是在缓冲池的一些数据脏页还是会刷新到磁盘。2 代表不完成full purge ,merge insert buffer操作,也 不将缓冲池中的数据脏页写回磁盘,而是将日志都写入日志文件。这样不会有任何事物会丢失,但是Mysql数据库下次启动时,会执行recovery
参数Innodb_force_recovery影响了整个InnoDB存储引擎的恢复状况。默认0

测试:

环境:innodb_fast_shutdown = 2

innodb_flush_log_at_trx_commit  = 2

sync_binlog   = 0

innodb_force_recovery影响整个InnoDB存储引擎的恢复状况。默认为0,表示当需要恢复时执行所有的

恢复操作。当不能进行有效的恢复操作时,mysql有可能无法启动,并记录下错误日志。
innodb_force_recovery可以设置为1-6,大的数字包含前面所有数字的影响。
当设置参数值大于0后,可以对表进行select,create,drop操作,但insert,update或者delete这类操作

是不允许的。
1(SRV_FORCE_IGNORE_CORRUPT):忽略检查到的corrupt页。
2(SRV_FORCE_NO_BACKGROUND):阻止主线程的运行,如主线程需要执行full purge操作,会导致crash。
3(SRV_FORCE_NO_TRX_UNDO):不执行事务回滚操作。
4(SRV_FORCE_NO_IBUF_MERGE):不执行插入缓冲的合并操作。
5(SRV_FORCE_NO_UNDO_LOG_SCAN):不查看重做日志,InnoDB存储引擎会将未提交的事务视为已提交。
6(SRV_FORCE_NO_LOG_REDO):不执行前滚的操作。

测试一
破坏xbb5.ibd表
删除了数据页

  1. innodb_force_recovery = 1-3  表不可用
  2. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysqld.sock' 错误
  3. innodb_force_recovery = 4-6  select * 可用,select count(*) 不准缺
  4. 报ERROR 2013 (HY000): Lost connection to MySQL server during query错误

测试二
创建事务,不提交

  1. root@test 04:32:32>begin;
  2. Query OK, 0 rows affected (0.01 sec)
  3.  
  4. root@test 04:33:14>update test set b = b+100;
  5. Query OK, 9999 rows affected (0.18 sec)
  6. Rows matched: 9999  Changed: 9999  Warnings: 0

innodb_force_recovery =0  要检查回滚操作

  1. 130626 16:32:20  InnoDB: Database was not shut down normally!
  2. InnoDB: Starting crash recovery.
  3. InnoDB: Reading tablespace information from the .ibd files...
  4. InnoDB: Restoring possible half-written data pages from the doublewrite
  5. InnoDB: buffer...
  6. InnoDB: 1 transaction(s) which must be rolled back or cleaned up
  7. InnoDB: in total 9999 row operations to undo
  8. InnoDB: Trx id counter is 0 12544
  9. InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
  10. InnoDB: Starting in background the rollback of uncommitted transactions
  11. 130626 16:32:21  InnoDB: Rolling back trx with id 0 12032, 9999 rows to undo
  12.  
  13. InnoDB: Progress in percents: 1130626 16:32:21  InnoDB: Started; log sequence number 0 4330016
  14. 130626 16:32:21 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
  15. 130626 16:32:21 [Note] Starting crash recovery...
  16. 130626 16:32:21 [Note] Crash recovery finished.
  17.  2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97130626 16:32:21 [Note] Event Scheduler: Loaded 0 events
  18. 130626 16:32:21 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
  19. Version: '5.1.57-log'  socket: '/tmp/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
  20.  98 99 100
  21. InnoDB: Rolling back of trx id 0 12032 completed
  22. 130626 16:32:21  InnoDB: Rollback of non-prepared transactions completed

如果回滚数据多,恢复就相对的慢
innodb_force_recovery =2 阻止主线程的运行,如主线程需要执行full purge操作,会导致crash。

  1. InnoDB: Starting crash recovery.
  2. InnoDB: Reading tablespace information from the .ibd files...
  3. InnoDB: Restoring possible half-written data pages from the doublewrite
  4. InnoDB: buffer...
  5. InnoDB: 1 transaction(s) which must be rolled back or cleaned up
  6. InnoDB: in total 9999 row operations to undo
  7. InnoDB: Trx id counter is 0 15616
  8. InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
  9. InnoDB: Starting in background the rollback of uncommitted transactions
  10. 130626 17:05:53  InnoDB: Rolling back trx with id 0 15104, 9999 rows to undo
  11.  
  12. InnoDB: Progress in percents: 1130626 17:05:53  InnoDB: Started; log sequence number 0 13016158
  13. InnoDB: !!! innodb_force_recovery is set to 2 !!!
  14. 130626 17:05:53 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
  15. 130626 17:05:53 [Note] Starting crash recovery...
  16. 130626 17:05:53 [Note] Crash recovery finished.
  17.  2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85130626 17:05:53 [Note] Event Scheduler: Loaded 0 events
  18. 130626 17:05:53 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
  19. Version: '5.1.57-log'  socket: '/tmp/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
  20.  86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  21. InnoDB: Rolling back of trx id 0 15104 completed
  22. 130626 17:05:53  InnoDB: Rollback of non-prepared transactions completed

innodb_force_recovery =3 不执行回滚操作

  1. 130626 16:33:53  InnoDB: Database was not shut down normally!
  2. InnoDB: Starting crash recovery.
  3. InnoDB: Reading tablespace information from the .ibd files...
  4. InnoDB: Restoring possible half-written data pages from the doublewrite
  5. InnoDB: buffer...
  6. InnoDB: 1 transaction(s) which must be rolled back or cleaned up
  7. InnoDB: in total 9999 row operations to undo
  8. InnoDB: Trx id counter is 0 13056
  9. InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
  10. 130626 16:33:53  InnoDB: Started; log sequence number 0 6497918
  11. InnoDB: !!! innodb_force_recovery is set to 3 !!!
  12. 130626 16:33:53 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
  13. 130626 16:33:53 [Note] Starting crash recovery...
  14. 130626 16:33:53 [Note] Crash recovery finished.
  15. 130626 16:33:53 [Note] Event Scheduler: Loaded 0 events
  16. 130626 16:33:53 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
  17. Version: '5.1.57-log'  socket: '/tmp/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

innodb_force_recovery =5 不查看重做日志,innodb存储引擎会将未提交的事务事务已经提交
此时数据已经被update

  1. +----+------+------+------+
  2. || b    | c    | d    |
  3. +----+------+------+------+
  4. |  1 |  101 |    1 |    1 |
  5. |  2 |  102 |    2 |    2 |
  6. |  3 |  103 |    3 |    3 |
  7. |  4 |  104 |    4 |    4 |
  8. |  5 |  105 |    5 |    5 |
  9. |  6 |  106 |    6 |    6 |
  10. |  7 |  107 |    7 |    7 |
  11. |  8 |  108 |    8 |    8 |
  12. |  9 |  109 |    9 |    9 |
  13. | 10 |  110 |   10 |   10 |
  14. +----+------+------+------+

innodb_force_recovery =6 不执行前滚操作,但是恢复的时候有回滚操作

  1. +----+------+------+------+
  2. || b    | c    | d    |
  3. +----+------+------+------+
  4. |  1 |  101 |    1 |    1 |
  5. |  2 |  102 |    2 |    2 |
  6. |  3 |  103 |    3 |    3 |
  7. |  4 |  104 |    4 |    4 |
  8. |  5 |  105 |    5 |    5 |
  9. |  6 |  106 |    6 |    6 |
  10. |  7 |  107 |    7 |    7 |
  11. |  8 |  108 |    8 |    8 |
  12. |  9 |  109 |    9 |    9 |
  13. | 10 |  110 |   10 |   10 |
  14. +----+------+------+------+
  1. 130626 16:44:29  InnoDB: Database was not shut down normally!
  2. InnoDB: Starting crash recovery.
  3. InnoDB: Reading tablespace information from the .ibd files...
  4. InnoDB: Restoring possible half-written data pages from the doublewrite
  5. InnoDB: buffer...
  6. InnoDB: Doing recovery: scanned up to log sequence number 0 8680656
  7. InnoDB: 1 transaction(s) which must be rolled back or cleaned up
  8. InnoDB: in total 9999 row operations to undo
  9. InnoDB: Trx id counter is 0 14080
  10. InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
  11. InnoDB: Starting in background the rollback of uncommitted transactions
  12. 130626 16:44:29  InnoDB: Rolling back trx with id 0 13057, 9999 rows to undo
  13.  
  14. InnoDB: Progress in percents: 1130626 16:44:29  InnoDB: Started; log sequence number 0 8680656
  15.  2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79130626 16:44:29 [Note] Event Scheduler: Loaded 0 events
  16. 130626 16:44:29 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
  17. Version: '5.1.57-log'  socket: '/tmp/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
  18.  80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  19. InnoDB: Rolling back of trx id 0 13057 completed
  20. 130626 16:44:29  InnoDB: Rollback of non-prepared transactions completed
  21. 130626 16:45:08 mysqld_safe Starting mysqld daemon with databases from /vobiledata/mysqldata
  22. 130626 16:45:08 [Note] Plugin 'FEDERATED' is disabled.
  23. 130626 16:45:08  InnoDB: Initializing buffer pool, size = 2.0G
  24. 130626 16:45:08  InnoDB: Completed initialization of buffer pool
  25. InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on
  26. InnoDB: Skipping log redo
  27. 130626 16:45:08  InnoDB: Started; log sequence number 0 0
  28. InnoDB: !!! innodb_force_recovery is set to 6 !!!
  29. 130626 16:45:08 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
  30. 130626 16:45:08 [Note] Starting crash recovery...
  31. 130626 16:45:08 [Note] Crash recovery finished.
  32. 130626 16:45:08 [Note] Event Scheduler: Loaded 0 events
  33. 130626 16:45:08 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
  34. Version: '5.1.57-log'  socket: '/tmp/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
  35. 130626 16:45:14  InnoDB: error: space object of table test/test,
  36. InnoDB: space id 3 did not exist in memory. Retrying an open.
  1. -+------+------+------+
  2. |  1 |  101 |    1 |    1 |
  3. |  2 |  102 |    2 |    2 |
  4. |  3 |  103 |    3 |    3 |
  5. |  4 |  104 |    4 |    4 |
  6. |  5 |  105 |    5 |    5 |
  7. |  6 |  106 |    6 |    6 |
  8. |  7 |  107 |    7 |    7 |
  9. |  8 |  108 |    8 |    8 |
  10. |  9 |  109 |    9 |    9 |
  11. | 10 |  110 |   10 |   10 |
  12. +----+------+------+------+
  1. 130626 16:44:29  InnoDB: Database was not shut down normally!
  2. InnoDB: Starting crash recovery.
  3. InnoDB: Reading tablespace information from the .ibd files...
  4. InnoDB: Restoring possible half-written data pages from the doublewrite
  5. InnoDB: buffer...
  6. InnoDB: Doing recovery: scanned up to log sequence number 0 8680656
  7. InnoDB: 1 transaction(s) which must be rolled back or cleaned up
  8. InnoDB: in total 9999 row operations to undo
  9. InnoDB: Trx id counter is 0 14080
  10. InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
  11. InnoDB: Starting in background the rollback of uncommitted transactions
  12. 130626 16:44:29  InnoDB: Rolling back trx with id 0 13057, 9999 rows to undo
  13.  
  14. InnoDB: Progress in percents: 1130626 16:44:29  InnoDB: Started; log sequence number 0 8680656
  15.  2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79130626 16:44:29 [Note] Event Scheduler: Loaded 0 events
  16. 130626 16:44:29 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
  17. Version: '5.1.57-log'  socket: '/tmp/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
  18.  80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  19. InnoDB: Rolling back of trx id 0 13057 completed
  20. 130626 16:44:29  InnoDB: Rollback of non-prepared transactions completed
  21. 130626 16:45:08 mysqld_safe Starting mysqld daemon with databases from /vobiledata/mysqldata
  22. 130626 16:45:08 [Note] Plugin 'FEDERATED' is disabled.
  23. 130626 16:45:08  InnoDB: Initializing buffer pool, size = 2.0G
  24. 130626 16:45:08  InnoDB: Completed initialization of buffer pool
  25. InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on
  26. InnoDB: Skipping log redo
  27. 130626 16:45:08  InnoDB: Started; log sequence number 0 0
  28. InnoDB: !!! innodb_force_recovery is set to 6 !!!
  29. 130626 16:45:08 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
  30. 130626 16:45:08 [Note] Starting crash recovery...
  31. 130626 16:45:08 [Note] Crash recovery finished.
  32. 130626 16:45:08 [Note] Event Scheduler: Loaded 0 events
  33. 130626 16:45:08 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
  34. Version: '5.1.57-log'  socket: '/tmp/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
  35. 130626 16:45:14  InnoDB: error: space object of table test/test,
  36. InnoDB: space id 3 did not exist in memory. Retrying an open.

解决数据库Operation not allowed when innodb_forced_recovery > 0的更多相关文章

  1. mydqldump 备份数单库 然后还原数据的时候报:ERROR 1881 (HY000) at line 52: Operation not allowed when innodb_forced_recovery > 0.

    修改my.cnf innodb_force_recovery = 1 修改为: innodb_force_recovery = 0

  2. db2数据库表操作错误SQL0668N Operation not allowed for reason code "1" on table "表". SQLSTATE=57016的解决方法

    错误sql Operation not allowed for reason code "1" on table "MARKET.PURE_USER".. SQ ...

  3. Operation not allowed after ResultSet closed--操作mysql数据库

    一个stmt多个rs进行操作.那么从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作.不能互相交替使用,会引起rs已经关闭错误——Operation not all ...

  4. SQLExecption:Operation not allowed after ResultSet closed解决办法

    原网址:http://blog.csdn.net/sku0923/article/details/1722370 一个stmt多个rs进行操作引起的ResultSet已经关闭错误 一个stmt多个rs ...

  5. Operation not allowed for reason code "7" on table 原因码 "7"的解决

    对表进行任何操作都不被允许,提示SQLSTATE=57016 SQLCODE=-668 ,原因码 "7"的错误:SQL0668N Operation not allowed for ...

  6. dbexpress连接mysql提示Operation not allowed on a unidirectional dataset

    最近刚接触delphi,在了解到dbExpress连接mysql的时候,出现了一些问题,特记录下 我遇到的问题有两个 1. TDBGrid --DataSet=TDataSource1 TDataSo ...

  7. db2报错 Operation not allowed for reason

    1.DB2数据库表操作错误SQL0668N Operation not allowed for reason code "1" on table "XXXX". ...

  8. ORA-00392: log 4 of thread 2 is being cleared, operation not allowed

     alter database open resetlogs或者 alter database open resetlogs upgrade报错:ORA-00392 在rman restore 还原数 ...

  9. java.sql.SQLException: Operation not allowed after ResultSet closed

    转自:http://blog.csdn.net/hellobobantang/article/details/7173622 java.sql.SQLException: Operation not ...

随机推荐

  1. DataTable复制自身行

    在我们工作的过程中有可能要使用DataTable产生一些重复数据(在不重复读取数据库的情况下) 无废话,直接上代码 DataTable复制自身一行(目的产生重复数据),已测试通过可直接复制 /// & ...

  2. Android--------- SD卡存储文件报错解决

    ##文件找不到 1.没有写write权限 2.没有判断文件夹是否存在,不存在则创建

  3. CSSOM视图模式

    相关技术文章: CSSOM视图模式(CSSOM View Module)相关整理 W3C CSSOM View Module

  4. attachEvent和addEventListener

    attachEvent和addEventListener在前端开发过程中经常性的使用,他们都可以用来绑定脚本事件,取代在html中写obj.onclick=method. 相同点: 它们都是dom对象 ...

  5. Hibernate配置文件中映射元素详解

    对象标识符号 在关系数据库表中,主键(Primary Key)用来识别记录,并保证每条记录的唯一性.在Java语言中,通过比较两个变量所引用对象的内存地址是否相同,或者比较两个变量引用的对象值是否相同 ...

  6. akoj-1140-英雄联盟阵营

    英雄联盟阵营 Time Limit:1000MS  Memory Limit:65536KTotal Submit:54 Accepted:16 Description 符文之地——瓦罗兰,作为最大的 ...

  7. php爬虫的两种思路

    写php爬虫可能最大的问题就是php脚本执行时间的问题了,对于这个问题,我找到了两种解决方法. 第一种通过代码set_time_limit(0)或者ini_set("max_executio ...

  8. LeetCode_Distinct Subsequences

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  9. Network Attack

    Network Attack Nicola regularly inspects the local networks for security issues. He uses a smart and ...

  10. java设计模式--结构型模式--享元模式

    享元模式 概述 运用共享技术有效地支持大量细粒度的对象. 适用性 当都具备下列情况时,使用Flyweight模式: 1.一个应用程序使用了大量的对象. 2.完全由于使用大量的对象,造成很大的存储开销. ...