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

客户数据库在运行中突然断电,当服务器重启发现MySQL无法启动,查看日志,报错如下:


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 http://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: http://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 have already crashed,
something is definitely wrong and this may fail.
Please help us make Percona Server better by reporting any
bugs at http://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
http://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

分析日志后发现,数据库无法重启的原因是因为ibdata1文件损坏,重启后无法正常恢复。

现在我们就需要跳过恢复步骤,修改my.cnf文件,在my.cnf中的[mysqld]中添加

innodb_force_recovery = 6
innodb_purge_threads = 0

innodbforcerecovery可以设置为1-6,大的数字包含前面所有数字的影响。
1. (SRVFORCEIGNORECORRUPT):忽略检查到的corrupt页。
2. (SRV
FORCENOBACKGROUND):阻止主线程的运行,如主线程需要执行full purge操作,会导致crash。
3. (SRVFORCENOTRXUNDO):不执行事务回滚操作。
4. (SRVFORCENOIBUFMERGE):不执行插入缓冲的合并操作。
5. (SRVFORCENOUNDOLOGSCAN):不查看重做日志,InnoDB存储引擎会将未提交的事务视为已提交。
6. (SRV
FORCENOLOG_REDO):不执行前滚的操作。

再次启动,如果还无法启动则删除数据目录datafile下的 ibdata1,ib_logfile*等文件。

启动后导出MySQL数据库,重新恢复即可。

时间: 2024-12-23 16:51:37

MySQL意外断电,InnoDB数据库恢复的相关文章

MySQL &#183; 引擎特性 &#183; InnoDB 崩溃恢复过程

MySQL · 引擎特性 · InnoDB 崩溃恢复过程 在前面两期月报中,我们详细介绍了 InnoDB redo log 和 undo log 的相关知识,本文将介绍 InnoDB 在崩溃恢复时的主要流程. 本文代码分析基于 MySQL 5.7.7-RC 版本,函数入口为 innobase_start_or_create_for_mysql,这是一个非常冗长的函数,本文只涉及和崩溃恢复相关的代码. 在阅读本文前,强烈建议翻阅我们之前的两期月报:1. MySQL · 引擎特性 · InnoDB

mysql 使用 Forcing InnoDB Recovery 恢复数据库

环境: CentOS release 6.6 (Final) Server version: 5.5.42-37.1-log Percona Server (GPL), Release 37.1, Revision 39acee0 现象: 数据库挂掉,重启报错 The server quit without updating PID file (/var/lib/mysql/cm.data.dingkai.com.pid).[失败] 日志: 150721 12:38:37  InnoDB: Da

MySQL 8.0 InnoDB Cluster 恢复故障成员

InnoDB Cluster 一节点丢失初始化故障节点 systemctl stop mysqld rm -rf /var/lib/mysql/* systemctl start mysqld 导出正常节点的数据库,并传到故障节点 mysqldump --all-databases --triggers --routines --events --quick --single-transaction --flush-logs --master-data=2 > dbs.dump scp dbs.

mysql数据库无法启动恢复 mysql数据库崩溃恢复 mysql数据库恢复

客户名称 保密 数据类型 mysql 5.5 innodb 数据容量 1500 MB 故障类型 服务器断电导致mysql无法启动.客户自己尝试innodb崩溃恢复从参数1-6无效. InnoDB: for more information. InnoDB: Error: trying to access page number 805281720 in space 0, InnoDB: space name .\ibdata1, InnoDB: which is outside the tabl

MySQL系列:innodb源码分析之redo log恢复

在上一篇<innodb源码分析之重做日志结构>中我们知道redo log的基本结构和日志写入步骤,那么redo log是怎么进行数据恢复的呢?在什么时候进行redo log的日志推演呢?redo log的推演只有在数据库异常或者关闭后,数据库重新启动时会进行日志推演,将数据库状态恢复到关闭前的状态.那么这个过程是怎么进行的呢?以下我们逐步来解析. 1.recv_sys_t结构 innodb在MySQL启动的时候,会对重做日志文件进行日志重做,重做日志是通过一个recv_sys_t的结构来进行数

MySQl的意外断电后无法启动

服务器意外断电后启动mysql数据库报错: Another MySQL daemon already running withthe same unix socket. 本地登录mysql数据库提示: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) 原因: mysql没有正常停止,机器重启后mysql.sock一直存在,但机器重启后my

Mysql 一次性备份导出/导入恢复所有数据库

Mysql 一次性备份导出/导入恢复所有数据库 有木有遇到过这种情况?电脑或者服务器需要重装系统?可是你电脑上存着n多个网站的数据库,怎么办?把数据库文件夹拷贝出来,重装系统之后再拷回去?如果你使用了InnoDB引擎,恐怕那样做会出麻烦的,一个一个往外导数据库?天哪,那要搞到何年何月啊?今天合肥网站制作向阳互联就来介绍一下如何一口气导出全部数据库,再把数据库恢复回来,其实利用mysqldump的-all-databases参数可以一口气把你数据库root用户下的所有数据库一口气导出到一个sql文

意外断电造成RAID 5阵列卡数据故障的恢复方法

由于技术的不断进步,不同型号的服务器出现RAID 5故障后,处理方法也不同.现在大型应用程序的网络拓朴结构,一般都采用C/S结构或B/S结构,至少需要一台装有大型数据库的服务器安放于中心机房.基于对服务器安全性与可靠性的考虑,通常会对服务器的磁盘采用磁盘阵列RAID(Redundant Array of Inexpensive Disk)进行磁盘冗余备份.其中RAID 5阵列级别为无独立校验磁盘的奇偶校验磁盘阵列,采用数据分块和独立存取技术,能在同一磁盘上并行处理多个访问请求,同时允许阵列中的任

mysql的InnoDB 数据库引擎TableSpace Exists 问题

Mysql数据库报错: ERROR 1813 (HY000): Tablespace '`coll`.`t1`' exists. 原因:在使用InnoDB引擎的数据库中,所有已经存在的表都使在使用InnoDB引擎的数据库中,所有已经存在的表都使用两个文件保存,假设表名为 t1,则在数据库的数据目录下会有两个文件, (1).frm 文件 数据表定义信息 (2).ibd 文件 数据表内容 处理方法: 在 MySql 5.6之前,这些文件都是可以公用的,如果.frm 文件丢失,则会报这个错,使用一个临