Mysql InnoDB Datafile .ibd is corrupted

本文介绍了一种解决InnoDB表空间损坏的方法,通过设置innodb_force_recovery参数为6,成功重启MySQL服务并修复损坏的数据库文件。文章还详细解释了innodb_force_recovery参数的不同级别及其作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在导入数据库一半的时候磁盘空间不足,导致数据库没有办法正常使用,查看了mysqld.log报了下面的错误

重启数据库,启动不起来。

2020-06-17T14:15:55.100958Z 0 [ERROR] InnoDB: Datafile './test_db/t_info.ibd' is corrupted. Cannot determine the space ID from the first 64 pages.
2020-06-17T14:15:55.103957Z 0 [ERROR] InnoDB: Checksum mismatch in datafile: ./test_db/t_comment.ibd, Space ID:2719, Flags: 33. Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html for how to resolve the issue.

解决办法:编辑/etc/my.cnf

加入:
innodb_force_recovery=6

在重启数据库service mysqld restart,问题解决了

 

原理分析

MySQL当innodb表空间损坏时候,可以使用innodb_force_recovery参数进行强制启动

innodb_force_recovery参数解释:
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):不执行前滚的操作。


修复表空间受损的表:
数据起来后,innodb类型的表不能写操作,但可以读,此时对表做check,查找到异常的表,读取出来,导入到myisam表里面,drop原表
然后在my.cnf中去掉innodb_force_recovery的设置,重启mysql
把myisam表转成innodb表;

版权声明:本文为优快云博主「巨行心」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/ssssny/java/article/details/77941024

iot-database | 2025-07-04T08:35:21.579433Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). iot-database | 2025-07-04T08:35:21.591130Z 0 [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata1 are 0x4800! iot-database | 2025-07-04 08:35:21 0x7fb876c66880 InnoDB: Assertion failure in thread 140430243424384 in file ut0ut.cc line 921 iot-database | InnoDB: We intentionally generate a memory trap. iot-database | InnoDB: Submit a detailed bug report to http://bugs.mysql.com. iot-database | InnoDB: If you get repeated assertion failures or crashes, even iot-database | InnoDB: immediately after the mysqld startup, there may be iot-database | InnoDB: corruption in the InnoDB tablespace. Please refer to iot-database | InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html iot-database | InnoDB: about forcing recovery. iot-database | 08:35:21 UTC - mysqld got signal 6 ; iot-database | This could be because you hit a bug. It is also possible that this binary iot-database | or one of the libraries it was linked against is corrupt, improperly built, iot-database | or misconfigured. This error can also be caused by malfunctioning hardware. iot-database | Attempting to collect some information that could help diagnose the problem. iot-database | As this is a crash and something is definitely wrong, the information iot-database | collection process might fail.
最新发布
07-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值