游乐游手机版
首页/数据库/文章详情

MySQL意外断电后InnoDB数据库恢复方法

时间:2026-08-20 21:12
客户数据库在运行过程中遇到突然断电,服务器重启后发现 MySQL 无法正常启动。查看错误日志后,报错信息如下:151105 11:24:52 mysqld_safe Starting mysqld daemon with databases from data mysql datafile1511

客户数据库在运行过程中遇到突然断电,服务器重启后发现 MySQL 无法正常启动。查看错误日志后,报错信息如下:

MySQL意外断电,InnoDB数据库恢复

151105 11:24:52 mysqld_safe Starting mysqld daemon with databases from /data/mysql/datafile
151105 11:24:52 [Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
151105 11:24:52 [Warning] Using unique option prefix myisam_recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
151105 11:24:52 InnoDB: The InnoDB memory heap is disabled
151105 11:24:52 InnoDB: Mutexes and rw_locks use GCC atomic builtins
151105 11:24:52 InnoDB: Compressed tables use zlib 1.2.3
151105 11:24:52 InnoDB: Initializing buffer pool, size = 512.0M
151105 11:24:52 InnoDB: Completed initialization of buffer pool
151105 11:24:52 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
151105 11:24:52 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...
151105 11:24:52 InnoDB: ERROR: We were only able to scan the log up to
InnoDB: 2735615488, but a checkpoint was at 2735615806.
InnoDB: It is possible that the database is now corrupt!
InnoDB: 3 transaction(s) which must be rolled back or cleaned up
InnoDB: in total 3 row operations to undo
InnoDB: Trx id counter is 6D84900
InnoDB: Last MySQL binlog file position 0 446116929, file name /data/mysql/binlog/mysql-bin.001288
InnoDB: Cleaning up trx with id 6D7C116
InnoDB: Cleaning up trx with id 6D74419
InnoDB: Cleaning up trx with id 6D6F27E
151105 11:24:52 InnoDB: Waiting for the background threads to start
151105 11:24:52 InnoDB: Assertion failure in thread 140108568532736 in file trx0purge.c line 848
InnoDB: Failing assertion: purge_sys->purge_trx_no <= purge_sys->rseg->last_trx_no
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to https://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: https://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
03:24:52 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we ha ve already crashed,
something is definitely wrong and this may fail.
Please help us make Percona Server better by reporting any
bugs at https://bugs.percona.com/

key_buffer_size=402653184
read_buffer_size=4194304
max_used_connections=0
max_threads=2002
thread_count=0
connection_count=0
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 16818378 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x40000
/usr/local/percona-server-5.5.38-35.2/bin/mysqld(my_print_stacktrace+0x2e)[0x7785ae]
/usr/local/percona-server-5.5.38-35.2/bin/mysqld(handle_fatal_signal+0x43a)[0x66a1da]
/lib64/libpthread.so.0[0x379c20f710]
/lib64/libc.so.6(gsignal+0x35)[0x379be32925]
/lib64/libc.so.6(abort+0x175)[0x379be34105]
/usr/local/percona-server-5.5.38-35.2/bin/mysqld[0x814fb0]
/usr/local/percona-server-5.5.38-35.2/bin/mysqld[0x8153f7]
/usr/local/percona-server-5.5.38-35.2/bin/mysqld[0x8e318f]
/usr/local/percona-server-5.5.38-35.2/bin/mysqld[0x8d98d5]
/usr/local/percona-server-5.5.38-35.2/bin/mysqld[0x813c4e]
/usr/local/percona-server-5.5.38-35.2/bin/mysqld[0x809d2c]
/lib64/libpthread.so.0[0x379c2079d1]
/lib64/libc.so.6(clone+0x6d)[0x379bee8b5d]
You may download the Percona Server operations manual by visiting
https://www.percona.com/software/percona-server/. You may find information
in the manual which will help you identify the cause of the crash.
151105 11:24:52 mysqld_safe mysqld from pid file /data/mysql/datafile/mysql.pid ended

通过分析 MySQL 启动日志可以判断,数据库重启失败的主要原因是 ibdata1 文件损坏,导致 InnoDB 在异常断电后无法完成正常恢复。

此时通常需要跳过 InnoDB 自动恢复流程,修改 my.cnf 配置文件,并在 my.cnf 的 [mysqld] 段中添加以下参数:

innodb_force_recovery = 6
innodb_purge_threads = 0

innodb_force_recovery 的取值范围为 1 到 6,数值越大,表示包含前面所有级别的恢复限制,常用于 MySQL 无法启动、InnoDB 表空间损坏、数据库异常断电后的紧急恢复场景。
1. (SRV_FORCE_IGNORE_CORRUPT):忽略检测到的损坏页。
2. (SRV_FORCE_NO_BACKGROUND):阻止主线程运行,如果主线程需要执行完整清理操作,可能会触发崩溃。
3. (SRV_FORCE_NO_TRX_UNDO):不执行事务回滚。
4. (SRV_FORCE_NO_IBUF_MERGE):不执行插入缓冲合并。
5. (SRV_FORCE_NO_UNDO_LOG_SCAN):不扫描 undo 日志,InnoDB 存储引擎会将未提交事务视为已提交。
6. (SRV_FORCE_NO_LOG_REDO):不执行 redo 前滚操作。

再次启动 MySQL,如果仍然无法启动,则可以尝试删除数据目录 datafile 下的 ibdata1、ib_logfile* 等相关文件。

数据库成功启动后,建议立即导出 MySQL 数据库并重新恢复,以完成 InnoDB 数据修复和业务数据重建。

来源:https://apiv1.oschina.net/oschinapi/blog/detail?id=526649
上一篇MySQL InnoDB中Redo Log为何对数据安全至关重要 下一篇phpMyAdmin修改字段字符集和排序规则的方法
本站内容用于信息整理与展示,如有侵权或内容问题请及时联系处理。

相关推荐

补充同频道和同主题内容,方便继续浏览更多相关内容。

同类最新

继续查看同栏目最近更新的文章。

更多
Redis是什么:核心特性、架构与应用场景解析
数据库 · 2026-09-01

Redis是什么:核心特性、架构与应用场景解析

Redis是一款基于内存的键值型NoSQL数据库,以超高读写速度和丰富的数据结构著称。本文系统梳理Redis的核心特性、架构组成、性能优势及典型应用场景,并通过与Memcached、MySQL、MongoDB的对比,帮助开发者快速判断Redis是否适合当前业务需求。

Windows 安装 MongoDB 完整图文教程
数据库 · 2026-09-01

Windows 安装 MongoDB 完整图文教程

本文详细介绍在 Windows 系统上安装 MongoDB 的完整流程。从官网下载 MSI 安装包开始,逐步演示自定义安装路径、配置 Windows 服务、跳过 MongoDB Compass 等关键选项,并提供通过系统服务列表验证安装是否成功的方法,帮助开发者快速搭建本地 MongoDB 环境。

Linux 安装 MongoDB 完整指南:依赖配置、环境变量与服务启动
数据库 · 2026-09-01

Linux 安装 MongoDB 完整指南:依赖配置、环境变量与服务启动

本文详解在 Linux 系统下安装 MongoDB 的完整流程,涵盖依赖包安装、二进制包下载解压、环境变量配置、数据与日志目录创建及服务启动验证。通过标准化命令与路径说明,帮助开发者快速完成部署并确认服务状态。

MacOS安装MongoDB完整教程
数据库 · 2026-09-01

MacOS安装MongoDB完整教程

本文介绍在MacOS系统下安装MongoDB的完整流程,涵盖下载、解压、目录配置、环境变量设置及服务启动。通过明确的命令与参数说明,帮助开发者快速完成环境搭建并验证安装结果。

Ubuntu系统安装与配置Redis完整指南
数据库 · 2026-09-01

Ubuntu系统安装与配置Redis完整指南

本文详解在Ubuntu系统中安装Redis的两种主流方式:apt在线安装与源码编译安装。涵盖版本选择逻辑、服务启停与状态检查、连接验证方法,以及在线练习工具与桌面GUI客户端的对比与使用建议,帮助开发者快速搭建并验证Redis运行环境。