摘要:今天给大家带来一篇MySQL数据库崩溃的修复案例

本文分享自华为云社区《记一次MySQL崩溃修复案例,再也不用删库跑路了》,作者: 冰 河。

问题描述

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

  1. -----------------------------------------
  2. 161108 23:36:45 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
  3. 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).
  4. 2022-08-25 23:36:46 5497 [Note] Plugin 'FEDERATED' is disabled.
  5. 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.
  6. 2022-08-25 23:36:46 5497 [Note] InnoDB: Using atomics to ref count buffer pool pages
  7. 2022-08-25 23:36:46 5497 [Note] InnoDB: The InnoDB memory heap is disabled
  8. 2022-08-25 23:36:46 5497 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
  9. 2022-08-25 23:36:46 5497 [Note] InnoDB: Memory barrier is not used
  10. 2022-08-25 23:36:46 5497 [Note] InnoDB: Compressed tables use zlib 1.2.3
  11. 2022-08-25 23:36:46 5497 [Note] InnoDB: Using CPU crc32 instructions
  12. 2022-08-25 23:36:46 5497 [Note] InnoDB: Initializing buffer pool, size = 16.0M
  13. 2022-08-25 23:36:46 5497 [Note] InnoDB: Completed initialization of buffer pool
  14. InnoDB: Database page corruption on disk or a failed
  15. InnoDB: file read of page 5.
  16. InnoDB: You may have to recover from a backup.
  17. 2022-08-25 23:36:46 7f11c48e1720 InnoDB: Page dump in ascii and hex (16384 bytes):
  18. len 16384; hex 7478d078000000050000000000000000000000000f271f4d000700000000000000000000000000000000001b4000000000000000000200f20000000000000006000000000000002d000000000000002e000000000000002f0000000000000030000000000(省略很多类似代码)
  19. InnoDB: End of page dump
  20. 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
  21. InnoDB: Page may be a transaction system page
  22. InnoDB: Database page corruption on disk or a failed
  23. InnoDB: file read of page 5.
  24. InnoDB: You may have to recover from a backup.
  25. InnoDB: It is also possible that your operating
  26. InnoDB: system has corrupted its own file cache
  27. InnoDB: and rebooting your computer removes the
  28. InnoDB: error.
  29. InnoDB: If the corrupt page is an index page
  30. InnoDB: you can also try to fix the corruption
  31. InnoDB: by dumping, dropping, and reimporting
  32. InnoDB: the corrupt table. You can use CHECK
  33. InnoDB: TABLE to scan your table for corruption.
  34. InnoDB: See also http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
  35. InnoDB: about forcing recovery.
  36. InnoDB: Ending processing because of a corrupt database page.
  37. 2022-08-25 23:36:46 7f11c48e1720 InnoDB: Assertion failure in thread 139714288817952 in file buf0buf.cc line 4201
  38. InnoDB: We intentionally generate a memory trap.
  39. InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
  40. InnoDB: If you get repeated assertion failures or crashes, even
  41. InnoDB: immediately after the mysqld startup, there may be
  42. InnoDB: corruption in the InnoDB tablespace. Please refer to
  43. InnoDB: http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
  44. InnoDB: about forcing recovery.
  45. 03:36:46 UTC - mysqld got signal 6 ;
  46. This could be because you hit a bug. It is also possible that this binary
  47. or one of the libraries it was linked against is corrupt, improperly built,
  48. or misconfigured. This error can also be caused by malfunctioning hardware.
  49. We will try our best to scrape up some info that will hopefully help
  50. diagnose the problem, but since we have already crashed,
  51. something is definitely wrong and this may fail.
  52. key_buffer_size=16777216
  53. read_buffer_size=262144
  54. max_used_connections=0
  55. max_threads=1000
  56. thread_count=0
  57. connection_count=0
  58. It is possible that mysqld could use up to
  59. key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 798063 K bytes of memory
  60. Hope that's ok; if not, decrease some variables in the equation.
  61. Thread pointer: 0x0
  62. Attempting backtrace. You can use the following information to find out
  63. where mysqld died. If you see no messages after this, something went
  64. terribly wrong...
  65. stack_bottom = 0 thread_stack 0x40000
  66. /usr/local/mysql/bin/mysqld(my_print_stacktrace+0x35)[0x8e64b5]
  67. /usr/local/mysql/bin/mysqld(handle_fatal_signal+0x41b)[0x652fbb]
  68. /lib64/libpthread.so.0(+0xf7e0)[0x7f11c44c77e0]
  69. /lib64/libc.so.6(gsignal+0x35)[0x7f11c315d625]
  70. /lib64/libc.so.6(abort+0x175)[0x7f11c315ee05]
  71. /usr/local/mysql/bin/mysqld[0xa585c5]
  72. /usr/local/mysql/bin/mysqld[0xa6c7b4]
  73. /usr/local/mysql/bin/mysqld[0xa6cbc7]
  74. /usr/local/mysql/bin/mysqld[0xa5bce2]
  75. /usr/local/mysql/bin/mysqld[0xa1e2ba]
  76. /usr/local/mysql/bin/mysqld[0xa0bf60]
  77. /usr/local/mysql/bin/mysqld[0x95a427]
  78. /usr/local/mysql/bin/mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x48)[0x58f788]
  79. /usr/local/mysql/bin/mysqld[0x6e4a36]
  80. /usr/local/mysql/bin/mysqld(_Z11plugin_initPiPPci+0xb3e)[0x6e826e]
  81. /usr/local/mysql/bin/mysqld[0x582d85]
  82. /usr/local/mysql/bin/mysqld(_Z11mysqld_mainiPPc+0x4d8)[0x587d18]
  83. /lib64/libc.so.6(__libc_start_main+0xfd)[0x7f11c3149d5d]
  84. /usr/local/mysql/bin/mysqld[0x57a019]
  85. The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
  86. information that should help you find out what is causing the crash.
  87. 161108 23:36:46 mysqld_safe mysqld from pid file /usr/local/mysql/var/VM_241_49_centos.pid ended
  88. ------------------------------------------------------------------------------

问题分析

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

  1. [mysqld]
  2. 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):不执行前滚的操作。

解决方案

一般修复方法参考:

第一种方法

建立一张新表:

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

把数据导进去

  1. insert into demo_bak select * from demo;

删除掉原表:

  1. drop table demo;

注释掉 innodb_force_recovery 之后,重启。

重命名:

  1. rename table demo_bak to demo;

最后改回存储引擎:

  1. alter table demo engine = innodb

第二种方法

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

  1. mysqldump -uroot -p123 test > test.sql

还原方法1:

  1. use test;
  2. source test.sql

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

  1. mysql -uroot -p123 test < test.sql;

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

第三种方法

1、配置my.cnf

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

2、导出数据脚本

  1. 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数据库

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

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

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

点击关注,第一时间了解华为云新鲜技术~

记一次血淋淋的MySQL崩溃修复案例的更多相关文章

  1. MySQL之——崩溃-修复损坏的innodb:innodb_force_recovery

    转: https://blog.csdn.net/l1028386804/article/details/77199194 一.问题描述 今天在线运行的一个mysql崩溃了. 查看错误日志,如下: - ...

  2. [转]MySQL之——崩溃-修复损坏的innodb:innodb_force_recovery

    原文 https://blog.csdn.net/l1028386804/article/details/77199194 1. mysql崩溃 --------------------------- ...

  3. 记一次裸迁 MySQL 经历

    记一次裸迁MySQL经历 前言:博主企业有一台企业阿里云机器,因为安装了云锁,造成服务器动不动就给我所死服务器.(就是那种 chattr +i /bin/bash ,分分钟日死狗 )趁着周末,Boos ...

  4. 阿里云ECS(linux)磁盘满触发的mysql的表异常修复案例

    阿里云ECS(linux)磁盘满触发的mysql的表异常修复案例 阿里云技术支持:完颜镇江 问题现象: 磁盘空间满了,第一想到的就是删除无用的服务日志或者升级数据盘. 通常是使用du –sh去分析目录 ...

  5. 沃森Mysql数据库修复工具

    华信Mysql数据库修复程序是由北京华信数据恢复中心独立研发.主要针对Mysql数据库损坏的恢复. 本程序可用于因为各种误操作而导致数据丢失的恢复,以及因为断电.陈列损坏.硬盘坏道等各种原因导致数据库 ...

  6. [转]Spark 踩坑记:数据库(Hbase+Mysql)

    https://cloud.tencent.com/developer/article/1004820 Spark 踩坑记:数据库(Hbase+Mysql) 前言 在使用Spark Streaming ...

  7. 基于Redo Log和Undo Log的MySQL崩溃恢复流程

    在之前的文章「简单了解InnoDB底层原理」聊了一下MySQL的Buffer Pool.这里再简单提一嘴,Buffer Pool是MySQL内存结构中十分核心的一个组成,你可以先把它想象成一个黑盒子. ...

  8. Linux系统cpu 100%修复案例

    Linux系统cpu 100%修复案例 ​阿里云技术支持团队:完颜镇江 案例背景: Linux主机连续三天CPU% 处理思路: 1.  登录服务器查看/var/log/messages+/var/lo ...

  9. SQL Server一致性错误修复案例总结

    今天遇到了一个关于数据库一致性错误的案例.海外工厂的一台SQL Server 2005(9.00.5069.00 Standard Edition)数据库在做DBCC CHECKDB的时候出现了一致性 ...

随机推荐

  1. LVS简单搭建(一)

    先说一个坑: 192.168.65.110为虚拟ip,在主节点设置(ifconfig  eth0:8 192.168.65.110/24),其他子节点要与主节点保持一致(ifconfig  lo:3  ...

  2. Failed to Setup IP tables: Unable to enable SKIP DNAT rule: (iptables failed: iptables --wait -t nat -I DOCKER -i br-b1938128a963

    报错信息:Failed to Setup IP tables: Unable to enable SKIP DNAT rule:  (iptables failed: iptables --wait ...

  3. # Vue3 toRef 和 toRefs 函数

    Vue3 toRef 和 toRefs 函数 上一篇博文介绍了 vue3 里面的 ref 函数和 reactive 函数,实现响应式数据,今天主要来说一下 toRef 函数和 toRefs 函数的基本 ...

  4. Tapdata PDK 生态共建计划启动!Doris、OceanBase、PolarDB、SequoiaDB 等十余家厂商首批加入

      2022年4月7日,Tapdata 正式启动 PDK 插件生态共建计划,致力于全面连接数据孤岛,加速构建更加开放的数据生态,以期让各行各业的使用者都能释放数据的价值,随时获取新鲜的数据.截至目前, ...

  5. Linux操作系统(7):rpm包管理和yum软件包在线管理

    一.rpm 包的管理 介绍:一种用于互联网下载包的打包及安装工具,它包含在某些 Linux 分发版中.它生成具有.RPM 扩展名的文件.RPM 是 RedHat Package Manager(Red ...

  6. MyBatis项目创建

    一.开发环境的准备 总览: mybatis搭建过程: 1.导入jar 2.创建mybatis的核心(全局)配置文件mybatis-config.xml,并配置 3.创建映射文件XxxMapper.xm ...

  7. 函数式(Functional)接口

    public class LambdaTest2 { @Test public void test1(){ happyTime(500, new Consumer<Double>() { ...

  8. MISC 2022/4/21 刷题记录-千字文

    1.千字文 得到名为png的无类型文件,010 Editor查看,png,改后缀,得到二维码 QR扫描,得到一句话"这里只有二维码" 思路不对,binwalk一下,发现有错误信息 ...

  9. zenmap安装

    发现最新版的KALI不带zenmap了,下面是安装步骤: 安装包转换工具:sudo apt-get install alien fakeroot -y 下载并转换:https://nmap.org/d ...

  10. word段落前的小点·

    原因是因为修改论文时,要求在论文的标题前加上 '·' 类似: 在网上搜索了半天,都是加符号,特此记录 解决: 1.文件---选项---显示--勾选段落标记 2.修改样式 至此,设置完毕,章节前的小点已 ...