首页 > 数据库 >MySQL数据页损坏,数据库启动不起来,再教你一招搞定!

MySQL数据页损坏,数据库启动不起来,再教你一招搞定!

时间:2024-10-15 21:22:12浏览次数:1  
标签:搞定 -- mysql ibd mysqld MySQL inno 再教 page

上一篇文章[MySQL数据库宕机,启动不起来,教你一招搞定!]介绍了数据页损坏一种修复方法,现在介绍另外一种方法,使用第三方工具Inno_space来进行修复。Inno_space 是一个专为解析和修复 InnoDB 表空间文件(.ibd)设计的命令行工具。它允许用户直接访问和操作这些文件,同时还支持修复 corrupt page 功能,如果遇到InnoDB 表文件中的page 损坏、实例无法启动的情况,inno_space 可以将corrupt page 跳过。从而保证实例能够启动,并且将绝大部分的数据找回。

 

inno_space安装

相关地址:https://github.com/baotiao/inno_space

首先,确保你的系统上已经安装了 makegcc。然后,通过以下命令克隆并编译 Inno_space:

git clone https://github.com/baotiao/inno_space.git

yum install gcc gcc-c++ make -y
cd inno_space
make -j 4

###只需要make, 就可以得到可执行文件, 做到开箱即用.

查看使用帮助:

# ./inno --help
Inno space
usage: inno [-h] [-f test/t.ibd] [-p page_num]
-h               -- show this help
-f test/t.ibd     -- ibd file
-c list-page-type     -- show all page type
-c index-summary       -- show indexes information
-c show-undo-file       -- show undo log file detail
-p page_num       -- show page information
-c show-records       -- show all records information
-u page_num       -- update page checksum
-d page_num       -- delete page
Example:
====================================================
Show sbtest1.ibd all page type
./inno -f ~/git/primary/dbs2250/sbtest/sbtest1.ibd -c list-page-type
Show sbtest1.ibd all indexes information
./inno -f ~/git/primary/dbs2250/sbtest/sbtest1.ibd -c index-summary
Show undo_001 all rseg information
./inno -f ~/git/primary/dbs2250/log/undo_001 -c show-undo-file
Show specify page information
./inno -f ~/git/primary/dbs2250/sbtest/sbtest1.ibd -p 10
Delete specify page
./inno -f ~/git/primary/dbs2250/test/t1.ibd -d 2
Update specify page checksum
./inno -f ~/git/primary/dbs2250/test/t1.ibd -u 2

 

修复损坏页

 

MySQL error日志报错如下:

2024-09-15T16:54:52.144828+08:00 0 [ERROR] InnoDB: Database page corruption on disk or a failed file read of page [page id: space=97, page number=2]. You may have to recover from a backup.
...................................
InnoDB: End of page dump
InnoDB: Page may be an 'inode' page
2024-09-15T16:54:53.031786+08:00 0 [ERROR] [FATAL] InnoDB: Aborting because of a corrupt database page in the system tablespace. Or, there was a failure in tagging the tablespace as corrupt.
2024-09-15 16:54:53 0x7f455affd700 InnoDB: Assertion failure in thread 139935856187136 in file ut0ut.cc line 921
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
...........................
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)[0xf7ab35]
/usr/local/mysql/bin/mysqld(handle_fatal_signal+0x4b9)[0x7faa09]
/lib64/libpthread.so.0(+0xf630)[0x7f45db520630]
/lib64/libc.so.6(gsignal+0x37)[0x7f45d9f08387]
/lib64/libc.so.6(abort+0x148)[0x7f45d9f09a78]
/usr/local/mysql/bin/mysqld(_Z18ut_print_timestampP8_IO_FILE+0x0)[0x7e993e]
/usr/local/mysql/bin/mysqld(_ZN2ib5fatalD1Ev+0xb3)[0x1276283]
/usr/local/mysql/bin/mysqld(_Z20buf_page_io_completeP10buf_page_tb+0x3ff)[0x12b276f]
/usr/local/mysql/bin/mysqld[0x12d48ac]
/usr/local/mysql/bin/mysqld(_Z24buf_read_page_backgroundRK9page_id_tRK11page_size_tb+0x2b)[0x12d4e2b]
/usr/local/mysql/bin/mysqld[0x12c3ca3]
/usr/local/mysql/bin/mysqld(buf_dump_thread+0x155)[0x12c52c5]
/lib64/libpthread.so.0(+0x7ea5)[0x7f45db518ea5]
/lib64/libc.so.6(clone+0x6d)[0x7f45d9fd0b0d]
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.

从日志报错看,page number=2 这个页存在问题。

修复方法:删除损坏的数据页(page number=2)

./inno -f /data/3307/data/dbtest/t_corrupt.ibd -d 2
File path /data/3307/data/dbtest/t_corrupt.ibd path, page num 2
=========================2's block==========================
FIL Header:
CheckSum: 2562232120
Page number: 2
Previous Page: 0
Next Page: 0
Page LSN: 4578585
Page Type: 3
Flush LSN: 0

Index Header:
Number of Directory Slots: 65535
Garbage Space: 65535
Number of Head Records: 0
Number of Records: 0
Max Trx id: 281474976710656
Page level: 0
Index ID: 18446744069414649855
==========================DeletePage==========================
CheckSum: 2562232120
crc 1973070033
Delete Page can't next or prev page, prev_page 0, next_page 0

更新数据页中checksum 值

./inno -f /data/3307/data/dbtest/t_corrupt.ibd -u 2
File path /data/3307/data/dbtest/t_corrupt.ibd path, page num 2
=========================2's block==========================
FIL Header:
CheckSum: 2562232120
Page number: 2
Previous Page: 0
Next Page: 0
Page LSN: 4578585
Page Type: 3
Flush LSN: 0

Index Header:
Number of Directory Slots: 65535
Garbage Space: 65535
Number of Head Records: 0
Number of Records: 0
Max Trx id: 281474976710656
Page level: 0
Index ID: 18446744069414649855
==========================DeletePage==========================
CheckSum: 2562232120
crc 1973070033
UpdateCheckSum 16384

验证数据

重新启动数据库

systemctl start mysqld

检查数据

mysql> select * from t_corrupt;
+------+
| id   |
+------+
|   1 |
|   2 |
|   3 |
|   4 |
...........
|   98 |
|   99 |
| 100 |
+------+
100 rows in set (0.00 sec)

可以正常查到数据,但是数据可能会减少了(数据少了删除掉的page的那部分数据),建议做个备份,然后重建该表,否则可能出现其它问题。

小结

损坏的页,可以通过工具删掉,删除的page数据可能会丢失,所以生产要慎重考虑。

关注我,学习更多的数据库知识!

标签:搞定,--,mysql,ibd,mysqld,MySQL,inno,再教,page
From: https://www.cnblogs.com/cheyunhua/p/18468503

相关文章

  • ElasticSearch的倒排索引和相关概念与MySQL的对比
    ElasticSearch的倒排索引和相关概念在用关系型数据库时,一些频繁用作查询条件的字段我们都会去建立索引来提升查询效率。在关系型数据库中,我们一般都采用B树索引进行存储,所以B树索引也是我们接触比较多的一种索引数据结构,但是在使用过程中,我们发现无法使用关系型数据库进行类......
  • Elasticsearch 倒排索引,ES相关概念对比MySQL
    elasticsearch之所以有如此高性能的搜索表现,正是得益于底层的倒排索引技术。什么是倒排索引?倒排索引的概念是基于MySQL这样的正向索引而言的。倒排索引中有两个非常重要的概念:文档(Document):用来搜索的数据,其中的每一条数据就是一个文档。例如一个网页、一个商品信息词条(Te......
  • Elasticsearch相关概念对比MySQL
    Elasticsearch相关概念对比MySQLElasticsearch中,文档指的是每一条数据,例如:我喜欢你。词条指的是将文档拆分成有意义的词语,例如之前的文档可拆成4个词条:我、喜欢、你。MySql中的概念Elasticsearch中的概念Table表Index索引,文档的集合Row一行行数据Document文档......
  • MySQL 全局表和表锁
    MySQL的锁可以分为全局表、表级表和行锁三类。全局锁加全局读锁,整个数据库处于只读状态,可以用于数据库备份flushtableswithreadlock利用重复读隔离级别,可以避免加全局锁mysqldump--single-transaction不推荐使用setglobalreadyonly=true使整库处于只读状态rea......
  • MySQL 唯一索引和普通索引
    唯一索引和普通索引的区别查询过程基本没有区别selectidfromTwherek=5InnoDB数据的读写单位是数据页,默认是16KB。更新过程普通索引可以使用changebuffer(会持久化),唯一索引不行。当需要更新一个数据页是,如果数据页在内存中就直接更新,如果数据页还没在内存中,在不......
  • MySQL 事务隔离级别实现原理
    InnoDB有两种读取数据的方式快照读/一致性读,MVCC当前读,获取读写锁后读取行的最新数据InnoDB用一致性读视图实现了MVCC,用于支持读已提交和可重复读隔离级别的实现。启动事务时立即创建视图starttransactionwithconsistentsnapshot快照读快照读/MVCCInnoDB每个事......
  • MySQL 行锁
    InnoDB和MyISAM对比Innodb支持崩溃恢复InnoDB支持事务InnoDB支持行锁B+Tree叶子节点存储内容不同MyISAM记录表行总数,InnoDB没有两阶段锁InnoDB读操作会使用MVCC,而写操作会使用写锁。InnoDB两阶段锁协议:行锁是在需要的时候加上的,并且要等到事务提交后才释放......
  • MySQL 选错索引
    查看执行计划选择的索引explainselect*fromtwhereabetween10000and10000;通过慢日志(slowlog)查看语句执行情况--启动慢日志SHOWVARIABLESLIKE'slow_query_log';--慢日志存储位置SHOWVARIABLESLIKE'slow_query_log_file';--慢日志阈值SHOWVARIABLES......
  • 倒排索引和ES相关概念对比MySQL
    1.倒排索引1.1倒排索引两个重要概念:文档:用来搜索的数据,其中的每一条数据就是一个文档。例如一个网页、一个商品信息以京东商城为列词条(Term):对文档数据或用户搜索数据,利用某种算法分词,得到的具备含义的词语就是词条。例如:我是中国人,就可以分为:我、是、中国人、中国、国人这......
  • C++使用MySQL官方的C API访问MySQL数据库
    这篇文章是一个简单的C++使用MySQL官方的CAPI访问MySQL数据库的代码示例。//main.h#ifndef_H_#define_H_#include<stdio.h>#include<Windows.h>#include<mysql.h>#pragmacomment(lib,"libmysql.lib")#defineinsert_prepare"insertintotest_tbvalue......