首页 > 数据库 >记一次MySQL崩溃修复案例,再也不用删库跑路了

记一次MySQL崩溃修复案例,再也不用删库跑路了

时间:2023-08-04 15:04:11浏览次数:41  
标签:案例 MySQL 36 删库 innodb InnoDB mysql mysqld local


大家好,我是冰河~~

今天给大家带来一篇MySQL数据库崩溃的修复案例,废话不多说,我们直接上正文,走起~~

问题描述

研究MySQL源代码,调试并压测MySQL源代码时,MySQL崩溃了!问题是它竟然崩溃了!而且还损坏了InnoDB文件!!还好是在调试环境下发生的,赶紧看看如何解决这个问题,经过一系列的查阅资料、验证、对比、MySQL源码调试跟踪、修复损坏的InnoDB文件、总结等流程,整理成此文,如果以后真的发生在线上的生产坏境,也不用担心是不是要跑路的问题了,可以分分钟搞定MySQL的崩溃问题了!!查看错误日志,如下:

-----------------------------------------

161108 23:36:45 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
2022-08-25 23:36:46 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-08-25 23:36:46 5497 [Note] Plugin 'FEDERATED' is disabled.
2022-08-25 23:36:46 7f11c48e1720 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
2022-08-25 23:36:46 5497 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-08-25 23:36:46 5497 [Note] InnoDB: The InnoDB memory heap is disabled
2022-08-25 23:36:46 5497 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2022-08-25 23:36:46 5497 [Note] InnoDB: Memory barrier is not used
2022-08-25 23:36:46 5497 [Note] InnoDB: Compressed tables use zlib 1.2.3
2022-08-25 23:36:46 5497 [Note] InnoDB: Using CPU crc32 instructions
2022-08-25 23:36:46 5497 [Note] InnoDB: Initializing buffer pool, size = 16.0M
2022-08-25 23:36:46 5497 [Note] InnoDB: Completed initialization of buffer pool

InnoDB: Database page corruption on disk or a failed

InnoDB: file read of page 5.

InnoDB: You may have to recover from a backup.
2022-08-25 23:36:46 7f11c48e1720 InnoDB: Page dump in ascii and hex (16384 bytes):

 len 16384; hex 7478d078000000050000000000000000000000000f271f4d000700000000000000000000000000000000001b4000000000000000000200f20000000000000006000000000000002d000000000000002e000000000000002f0000000000000030000000000(省略很多类似代码)

InnoDB: End of page dump
2022-08-25 23:36:46 7f11c48e1720 InnoDB: uncompressed page, stored checksum in field1 1954074744, calculated checksums for field1: crc32 993334256, innodb 2046145943, none 3735928559, stored checksum in field2 1139795846, calculated checksums for field2: crc32 993334256, innodb 1606613742, none 3735928559, page LSN 0 254222157, low 4 bytes of LSN at page end 254221236, page number (if stored to page already) 5, space id (if created with >= MySQL-4.1.1 and stored already) 0

InnoDB: Page may be a transaction system page

InnoDB: Database page corruption on disk or a failed

InnoDB: file read of page 5.

InnoDB: You may have to recover from a backup.

InnoDB: It is also possible that your operating

InnoDB: system has corrupted its own file cache

InnoDB: and rebooting your computer removes the

InnoDB: error.

InnoDB: If the corrupt page is an index page

InnoDB: you can also try to fix the corruption

InnoDB: by dumping, dropping, and reimporting

InnoDB: the corrupt table. You can use CHECK

InnoDB: TABLE to scan your table for corruption.

InnoDB: See also http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html

InnoDB: about forcing recovery.

InnoDB: Ending processing because of a corrupt database page.
2022-08-25 23:36:46 7f11c48e1720  InnoDB: Assertion failure in thread 139714288817952 in file buf0buf.cc line 4201

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.6/en/forcing-innodb-recovery.html

InnoDB: about forcing recovery.

03:36:46 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.

key_buffer_size=16777216

read_buffer_size=262144

max_used_connections=0

max_threads=1000

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 = 798063 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/mysql/bin/mysqld(my_print_stacktrace+0x35)[0x8e64b5]

/usr/local/mysql/bin/mysqld(handle_fatal_signal+0x41b)[0x652fbb]

/lib64/libpthread.so.0(+0xf7e0)[0x7f11c44c77e0]

/lib64/libc.so.6(gsignal+0x35)[0x7f11c315d625]

/lib64/libc.so.6(abort+0x175)[0x7f11c315ee05]

/usr/local/mysql/bin/mysqld[0xa585c5]

/usr/local/mysql/bin/mysqld[0xa6c7b4]

/usr/local/mysql/bin/mysqld[0xa6cbc7]

/usr/local/mysql/bin/mysqld[0xa5bce2]

/usr/local/mysql/bin/mysqld[0xa1e2ba]

/usr/local/mysql/bin/mysqld[0xa0bf60]

/usr/local/mysql/bin/mysqld[0x95a427]

/usr/local/mysql/bin/mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x48)[0x58f788]

/usr/local/mysql/bin/mysqld[0x6e4a36]

/usr/local/mysql/bin/mysqld(_Z11plugin_initPiPPci+0xb3e)[0x6e826e]

/usr/local/mysql/bin/mysqld[0x582d85]

/usr/local/mysql/bin/mysqld(_Z11mysqld_mainiPPc+0x4d8)[0x587d18]

/lib64/libc.so.6(__libc_start_main+0xfd)[0x7f11c3149d5d]

/usr/local/mysql/bin/mysqld[0x57a019]

The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains

information that should help you find out what is causing the crash.

161108 23:36:46 mysqld_safe mysqld from pid file /usr/local/mysql/var/VM_241_49_centos.pid ended

------------------------------------------------------------------------------

问题分析

从日志中可以看出是innodb引擎出了问题。日志里提示到 http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html查看强制恢复的方法。在mysql的配置文件my.cnf里找到 [mysqld]字段下,添加 innodb_force_recovery=1:

[mysqld]
innodb_force_recovery = 1

如果innodb_force_recovery = 1不生效,则可尝试2——6几个数字

然后重启mysql,重启成功。然后使用mysqldump或 pma 导出数据,执行修复操作等。修复完成后,把该参数注释掉,还原默认值0。

配置文件的参数:innodb_force_recovery

innodb_force_recovery影响整个InnoDB存储引擎的恢复状况。默认为0,表示当需要恢复时执行所有的恢复操作(即校验数据页/purge undo/insert buffer merge/rolling back&forward),当不能进行有效的恢复操作时,mysql有可能无法启动,并记录错误日志;

innodb_force_recovery可以设置为1-6,大的数字包含前面所有数字的影响。当设置参数值大于0后,可以对表进行select,create,drop操作,但insert,update或者delete这类操作是不允许的。

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

解决方案

一般修复方法参考:

第一种方法

建立一张新表:

create table demo_bak  #和原表结构一样,只是把INNODB改成了MYISAM。

把数据导进去

insert into demo_bak select * from demo;

删除掉原表:

drop table demo;

注释掉 innodb_force_recovery 之后,重启。

重命名:

rename table demo_bak to demo;

最后改回存储引擎:

alter table demo engine = innodb

第二种方法

另一个方法是使用mysqldump将表格导出,然后再导回到InnoDB表中。这两种方法的结果是相同的。
备份导出(包括结构和数据):

mysqldump -uroot -p123 test > test.sql

还原方法1:

use test;
source test.sql

还原方法2(系统命令行):

mysql -uroot -p123 test < test.sql;

注意,CHECK TABLE命令在InnoDB数据库中基本上是没有用的。

第三种方法

1、配置my.cnf

配置innodb_force_recovery = 1或2——6几个数字,重启MySQL

2、导出数据脚本

mysqldump -uroot -p123 test > test.sql

导出SQL脚本。或者用Navicat将所有数据库/表导入到其他服务器的数据库中。

注意:这里的数据一定要备份成功。然后删除原数据库中的数据。

3、删除ib_logfile0、ib_logfile1、ibdata1

备份MySQL数据目录下的ib_logfile0、ib_logfile1、ibdata1三个文件,然后将这三个文件删除

4、配置my.cnf

将my.cnf中innodb_force_recovery = 1或2——6几个数字这行配置删除或者配置为innodb_force_recovery = 0,重启MySQL服务

5、将数据导入MySQL数据库

mysql -uroot -p123 test < test.sql; 或者用Navicat将备份的数据导入到数据库中。

此种方法下要注意的问题:

  • ib_logfile0、ib_logfile1、ibdata1这三个文件一定要先备份后删除;
  • 一定要确认原数据导出成功了
  • 当数据导出成功后,删除原数据库中的数据时,如果提示不能删除,可在命令行进入MySQL的数据目录,手动删除相关数据库的文件夹或者数据库文件夹下的数据表文件,前提是数据一定导出或备份成功。

好了,如果文章对你有点帮助,记得给冰河一键三连哦,欢迎将文章转发给更多的小伙伴,冰河将不胜感激~~

写在最后

如果你想进大厂,想升职加薪,或者对自己现有的工作比较迷茫,都可以私信我交流,希望我的一些经历能够帮助到大家~~

标签:案例,MySQL,36,删库,innodb,InnoDB,mysql,mysqld,local
From: https://blog.51cto.com/binghe001/6962610

相关文章

  • 视频融合平台视频汇聚平台LiteCVR接入协议通道播放失败反馈处理案例
    我们近期正在整理以前到近期的用户反馈,今后将陆续把已经整理好的案列以图文的形式分享给大家参考。有用户反馈称,在他们现场部署了LiteCVR平台后,NVR设备通过国标GB28181协议成功接入到LiteCVR。尽管设备和通道都显示为在线状态,但是他们发现部分通道的视频无法正常播放。因此,他们请求......
  • 案例7-Unittest测试框架定制
    需求描述假设由你们公司的已有一套前辈开发的基于unittest的测试框架,现在交由你进行维护。领导另外提出了一些新的需求,比如:为用例增加优先级功能bvt及p0-p2,并支持按优先级筛选用例。为用例添加状态功能,包括实现中、完成、废弃等,默认只运行完成的用例为用例添加负责人,并在......
  • springboot+mysql简单的登录系统
    springboot+mysql简单的登录系统pom.xml<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation=&q......
  • PLC顺序控制指令的应用案例
    本节内容主要介绍程序控制指令中的顺序控制指令,该指令主要用于一些有明显的动作顺序控制,且包含一系列重复执行的操作时,就可以使用顺序控制指令,这样使程序更清晰,动作过程更好理解,也便于电气设计人员进行程序设计。顺序控制的程序设计一般会有多种不同的类型,在进行顺序控制......
  • Unity的IPreprocessShaders:深入解析与实用案例
    UnityIPreprocessShadersUnityIPreprocessShaders是Unity引擎中的一个非常有用的功能,它可以让开发者在编译Shader时自定义哪些操作需要被执行。这个可以帮助开发者更好地控制Shader的编译过程,确保在编译Shader时执行必要的操作。在本文中,我们介绍UnityIPreprocessShaders的使......
  • linux如何安装mysql客户端(只是客户端)
    原文链接:https://blog.csdn.net/qq_34208660/article/details/121267333MySQL::DownloadMySQLCommunityServerhttps://dev.mysql.com/downloads/mysql/下载mysql-client,点击LookingforthelatestGAversion跳到5.7.36版本   rz上传到linux服务器使用r......
  • 【答疑】jsonpath和beanshell配合使用案例
    问题今天提升群小伙伴问了这样一个问题:接口返回如下(list元素个数不确定),需要提取所有的iautoid,然后用逗号拼接起来,如果是如下返回,需要得到的结果是1687283717749342208,1679392630364184576,后续请求需要使用{ "data":{ "firstPage":true, "lastPage":false, "list":......
  • MySQL中char与varchar的区别:存储机制、性能差异、适用场景
    引用链接:https://www.maoyingdong.com/mysql-char-vs-varchar/ 在MySQL中,varchar和char都可以用来存储字符串。从语义上看,varchar是变长的(Variable-length),char是定长的(Fixed-length)。本文基于MySQL5.7版本,从varchar和char的语义,到存储引擎底层存储机制,探讨它们在存......
  • MySql基础及约束
    review#数据库#MySQL数据库数据库基础知识存储数据的仓库,数据是有组织的存储的英文:database,简称DB数据库管理系统是管理数据库的大型软件,英文为DataBaseManagermentSystem简称DBMS关系表数据库SQl是结构化查询语言,用来操作关系型数据库,定义了操作所有关系型数据库......
  • ChatGPT 问答00011 Spring框架事件驱动使用案例
    以下是一个使用Spring框架的事件驱动机制的简单案例:定义事件类:publicclassOrderEventextendsApplicationEvent{privateOrderorder;publicOrderEvent(Objectsource,Orderorder){super(source);this.order=order;}public......