解决数据库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表
删除了数据页

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

测试二
创建事务,不提交

[email protected] 04:32:32>begin;
Query OK, 0 rows affected (0.01 sec)

[email protected] 04:33:14>update test set b = b+100;
Query OK, 9999 rows affected (0.18 sec)
Rows matched: 9999  Changed: 9999  Warnings: 0

innodb_force_recovery =0  要检查回滚操作

130626 16:32:20  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 12544
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
InnoDB: Starting in background the rollback of uncommitted transactions
130626 16:32:21  InnoDB: Rolling back trx with id 0 12032, 9999 rows to undo

InnoDB: Progress in percents: 1130626 16:32:21  InnoDB: Started; log sequence number 0 4330016
130626 16:32:21 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 16:32:21 [Note] Starting crash recovery...
130626 16:32:21 [Note] Crash recovery finished.
 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
130626 16:32:21 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: ‘5.1.57-log‘  socket: ‘/tmp/mysqld.sock‘  port: 3306  MySQL Community Server (GPL)
 98 99 100
InnoDB: Rolling back of trx id 0 12032 completed
130626 16:32:21  InnoDB: Rollback of non-prepared transactions completed

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

InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 15616
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
InnoDB: Starting in background the rollback of uncommitted transactions
130626 17:05:53  InnoDB: Rolling back trx with id 0 15104, 9999 rows to undo

InnoDB: Progress in percents: 1130626 17:05:53  InnoDB: Started; log sequence number 0 13016158
InnoDB: !!! innodb_force_recovery is set to 2 !!!
130626 17:05:53 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 17:05:53 [Note] Starting crash recovery...
130626 17:05:53 [Note] Crash recovery finished.
 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
130626 17:05:53 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: ‘5.1.57-log‘  socket: ‘/tmp/mysqld.sock‘  port: 3306  MySQL Community Server (GPL)
 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
InnoDB: Rolling back of trx id 0 15104 completed
130626 17:05:53  InnoDB: Rollback of non-prepared transactions completed

innodb_force_recovery =3 不执行回滚操作

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

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

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

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

+----+------+------+------+
| a  | b    | c    | d    |
+----+------+------+------+
|  1 |  101 |    1 |    1 |
|  2 |  102 |    2 |    2 |
|  3 |  103 |    3 |    3 |
|  4 |  104 |    4 |    4 |
|  5 |  105 |    5 |    5 |
|  6 |  106 |    6 |    6 |
|  7 |  107 |    7 |    7 |
|  8 |  108 |    8 |    8 |
|  9 |  109 |    9 |    9 |
| 10 |  110 |   10 |   10 |
+----+------+------+------+
130626 16:44:29  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 8680656
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 14080
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
InnoDB: Starting in background the rollback of uncommitted transactions
130626 16:44:29  InnoDB: Rolling back trx with id 0 13057, 9999 rows to undo

InnoDB: Progress in percents: 1130626 16:44:29  InnoDB: Started; log sequence number 0 8680656
 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
130626 16:44:29 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: ‘5.1.57-log‘  socket: ‘/tmp/mysqld.sock‘  port: 3306  MySQL Community Server (GPL)
 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
InnoDB: Rolling back of trx id 0 13057 completed
130626 16:44:29  InnoDB: Rollback of non-prepared transactions completed
130626 16:45:08 mysqld_safe Starting mysqld daemon with databases from /vobiledata/mysqldata
130626 16:45:08 [Note] Plugin ‘FEDERATED‘ is disabled.
130626 16:45:08  InnoDB: Initializing buffer pool, size = 2.0G
130626 16:45:08  InnoDB: Completed initialization of buffer pool
InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on
InnoDB: Skipping log redo
130626 16:45:08  InnoDB: Started; log sequence number 0 0
InnoDB: !!! innodb_force_recovery is set to 6 !!!
130626 16:45:08 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 16:45:08 [Note] Starting crash recovery...
130626 16:45:08 [Note] Crash recovery finished.
130626 16:45:08 [Note] Event Scheduler: Loaded 0 events
130626 16:45:08 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: ‘5.1.57-log‘  socket: ‘/tmp/mysqld.sock‘  port: 3306  MySQL Community Server (GPL)
130626 16:45:14  InnoDB: error: space object of table test/test,
InnoDB: space id 3 did not exist in memory. Retrying an open.
-+------+------+------+
|  1 |  101 |    1 |    1 |
|  2 |  102 |    2 |    2 |
|  3 |  103 |    3 |    3 |
|  4 |  104 |    4 |    4 |
|  5 |  105 |    5 |    5 |
|  6 |  106 |    6 |    6 |
|  7 |  107 |    7 |    7 |
|  8 |  108 |    8 |    8 |
|  9 |  109 |    9 |    9 |
| 10 |  110 |   10 |   10 |
+----+------+------+------+
130626 16:44:29  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 0 8680656
InnoDB: 1 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 9999 row operations to undo
InnoDB: Trx id counter is 0 14080
InnoDB: Last MySQL binlog file position 0 920753, file name /vobiledata/mysqllog/mysql-bin.000245
InnoDB: Starting in background the rollback of uncommitted transactions
130626 16:44:29  InnoDB: Rolling back trx with id 0 13057, 9999 rows to undo

InnoDB: Progress in percents: 1130626 16:44:29  InnoDB: Started; log sequence number 0 8680656
 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
130626 16:44:29 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: ‘5.1.57-log‘  socket: ‘/tmp/mysqld.sock‘  port: 3306  MySQL Community Server (GPL)
 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
InnoDB: Rolling back of trx id 0 13057 completed
130626 16:44:29  InnoDB: Rollback of non-prepared transactions completed
130626 16:45:08 mysqld_safe Starting mysqld daemon with databases from /vobiledata/mysqldata
130626 16:45:08 [Note] Plugin ‘FEDERATED‘ is disabled.
130626 16:45:08  InnoDB: Initializing buffer pool, size = 2.0G
130626 16:45:08  InnoDB: Completed initialization of buffer pool
InnoDB: The user has set SRV_FORCE_NO_LOG_REDO on
InnoDB: Skipping log redo
130626 16:45:08  InnoDB: Started; log sequence number 0 0
InnoDB: !!! innodb_force_recovery is set to 6 !!!
130626 16:45:08 [Note] Recovering after a crash using /vobiledata/mysqllog/mysql-bin
130626 16:45:08 [Note] Starting crash recovery...
130626 16:45:08 [Note] Crash recovery finished.
130626 16:45:08 [Note] Event Scheduler: Loaded 0 events
130626 16:45:08 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: ‘5.1.57-log‘  socket: ‘/tmp/mysqld.sock‘  port: 3306  MySQL Community Server (GPL)
130626 16:45:14  InnoDB: error: space object of table test/test,
InnoDB: space id 3 did not exist in memory. Retrying an open.
时间: 2024-10-18 00:44:16

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

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

原网址:http://blog.csdn.net/sku0923/article/details/1722370 一个stmt多个rs进行操作引起的ResultSet已经关闭错误 一个stmt多个rs进行操作. 那么从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作. 不能互相交替使用,会引起rs已经关闭错误. 错误的代码如下:  stmt=conn.createStatement(); rs=stmt.executeQuery("select * from

db2报错 Operation not allowed for reason

1.DB2数据库表操作错误SQL0668N Operation not allowed for reason code "1" on table "XXXX". SQLSTATE=57016的解决方法 The table is in Check Pending state. The integrity of the table is not enforced and the content of the table may be invalid. An operat

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

转自:http://blog.csdn.net/hellobobantang/article/details/7173622 java.sql.SQLException: Operation not allowed after ResultSet closedat com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)at com.mysql.jdbc.SQLError.createSQLException(SQLError.

sql点滴39—解决数据库日志文件过大的问题

原文:sql点滴39-解决数据库日志文件过大的问题 随着数据库使用时间增长,日志文件也在不停的增大,这里介绍几种方法减小这个文件的方法. 1.直接删除log文件 分离数据库.分离数据库之前一定要做好数据库的全备份,选择数据库——右键——任务——分离,如下图 将日志文件和数据文件复制粘贴到另外一个文件夹中以防万一.删除链接,如下图 直接删除日志文件,然后再附加数据库,如下图 附加的时候会自动将ldf文件和mdf文件都附加上,但是会提示找不到ldf文件,没关系,选中ldf文件这一行,点击下面的删除按

错误:Operation not allowed after ResultSet closed

?????????????????? 一.错误信息 Operation not allowed after ResultSet closed  意为:在结果集关闭不允许操作 二.为什么resultSet会自动关闭 错误关键在于:一个stmt有多个rs进行操作 正确操作应该:从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作.不能互相交替使用:   或者   不用的rs,使用不同的stmt 错误的代码如下: stmt=conn.createStatement()

数据库互转工具 DB2DB v1.0

最近公司有一个项目,需要把原来的系统从 MSSQL 升迁到阿里云RDS(MySQL)上面.为便于测试,所以需要把原来系统的所有数据表以及测试数据转换到 MySQL 上面.在百度上找了很多方法,有通过微软 DTS 的,也有使用 mss2sql 工具进行转换的.使用 DTS 需要预先创建好数据表,否则新迁移的数据库是没有主键的.而 mss2sql 工具可以解决以上问题,但转换速度非常慢!我需要转换 3000 万的数据,在一台相当不错的服务器上面,也需要几天几夜才能转换完成.而 DB2DB 就是在这样

Java程序中解决数据库超时与死锁

Java程序中解决数据库超时与死锁 2011-06-07 11:09 佚名 帮考网 字号:T | T Java程序中解决数据库超时与死锁,每个使用关系型数据库的程序都可能遇到数据死锁或不可用的情况,而这些情况需要在代码中编程来解决.本文主要介绍与数据库事务死锁等情况相关的重试逻辑概念. AD: Java程序中解决数据库超时与死锁,每个使用关系型数据库的程序都可能遇到数据死锁或不可用的情况,而这些情况需要在代码中编程来解决;本文主要介绍与数据库事务死锁等情况相关的重试逻辑概念,此外,还会探讨如何避

Operation not allowed on a unidirectional dataset错误?

关于网友提出的“ Operation not allowed on a unidirectional dataset错误?”问题疑问,本网通过在网上对“ Operation not allowed on a unidirectional dataset错误?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下: 问题: Operation not allowed on a unidirectional dataset错误?描述: 我在使用TSQLQuery组件查询Oracle数据库中的表

探索Oracle之数据库升级十 12c(12.1.0.2)CPU 19774304

探索Oracle之数据库升级十 12c(12.1.0.2)CPU 19774304 一.   补丁描述 参考metalink doc: (Doc ID 19774304.8) Bug19774304 - 12.1.0.2 Bundle Patch 2 for Engineered Systems and DB In-Memory (Nov2014) (Doc ID 19774304.8) 二.   补丁包含 19649591 DATABASE BUNDLE PATCH 12.1.0.2.2 (O