search
HomeDatabaseMysql TutorialMySQL单表ibd文件恢复_MySQL

bitsCN.com

前言:

随着innodb的普及,innobackup也成为了主流备份方式。物理备份对于新建slave,全库恢复的需求都能从容应对。

但当面临单表数据误删,或者单表误drop的情况,如果使用物理全备进行恢复呢? 

下文将进行详细分析。 

恢复过程中需要用到的工具,percona data recover tool : https://launchpad.net/percona-innodb-recovery-tool

 

情况一:误删部分数据,需要用最近一次备份覆盖

来自同一台机器的ibd恢复覆盖,且备份后table没有被recreate过。

这种情况是最简单的,备份时的ibd文件(后称老ibd)中的space id和index id 与 新ibd的space id 和index id一致。

且和ibdata文件中的space id和index id一致。因此,物理文件可以直接覆盖做恢复。

以下是详细步骤

Step -1 : 物理备份

 innobackupex --defaults-file=/usr/local/mysql3321/my.cnf --socket=/xfs/mysql3321/mysql.sock --user=root --password=password /xfs/backup/

Step 0 : apply log

innobackupex --apply-log --defaults-file=/usr/local/mysql3321/my.cnf  /xfs/backup/2012-10-17_11-29-20/

Step 1 : 备份现在的ibd文件(可选)

cp -a testibd.ibd testibd.bak

Step 2 : 舍弃现在ibd文件

mysql> alter table testibd discard tablespace

Step 3 : 复制备份ibd文件

shell> cp /xfs/backup/2012-10-17_11-29-20/test/testibd.ibd /xfs/mysql3321/test/ 

shell> chown mysql:mysql /xfs/mysql3321/test/testibd.ibd

Step 4 : 导入ibd文件

mysql> alter table testibd import tablespace

 

情况二:误删 table,表结构已经被drop了

这种情况稍复杂,不过恢复过程还是比较容易操作的。由于table被drop后的space id会留空因此备份文件的space id不会被占用。

我们只需要重建表结构,然后把ibdata中该表的space id还原,物理文件可以直接覆盖做恢复了。

Step 1 : 重建表

mysql> create table testibd (UserID int);

Step 2 : 关闭mysql服务(必须)

shell> service mysqld3321 stop

Step 3: 准备ibd文件  apply log

shell> innobackupex --apply-log --defaults-file=/usr/local/mysql3321/my.cnf  /xfs/backup/2012-10-17_11-29-20/

Step 4 : 备份现在的ibd文件(可选)

cp -a testibd.ibd testibd.bak

Step 5 : 复制备份ibd文件

shell> cp -a /xfs/backup/2012-10-17_11-29-20/test/testibd.ibd /xfs/mysql3321/test/ 

shell> chown mysql:mysql /xfs/mysql3321/test/testibd.ibd

Step 6 : 使用percona recovery tool 修改ibdata

shell> /root/install/percona-data-recovery-tool-for-innodb-0.5/ibdconnect -o /xfs/mysql3321/ibdata1 -f /xfs/mysql3321/test/testibd.ibd -d test -t testibd

输出结果
Initializing table definitions...Processing table: SYS_TABLES - total fields: 10 - nullable fields: 6 - minimum header size: 5 - minimum rec size: 21 - maximum rec size: 555Processing table: SYS_INDEXES - total fields: 9 - nullable fields: 5 - minimum header size: 5 - minimum rec size: 29 - maximum rec size: 165Setting SPACE=1 in SYS_TABLE for `test`.`testibd`Check if space id 1 is already usedPage_id: 8, next page_id: 4294967295Record position: 65Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 8 50 3 2 0 0 0 0 0 Db/table: infimumSpace id: 1768842857 (0x696E6669)Next record at offset: 8DRecord position: 8DChecking field lengths for a row (SYS_TABLES): OFFSETS: 16 11 17 24 32 36 40 48 52 52 Db/table: SYS_FOREIGNSpace id: 0 (0x0)Next record at offset: D5Record position: D5Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 16 22 29 37 41 45 53 57 57 Db/table: SYS_FOREIGN_COLSSpace id: 0 (0x0)Next record at offset: 122Record position: 122Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 12 18 25 33 37 41 49 53 53 Db/table: test/testibdSpace id: 2 (0x2)Next record at offset: 74Space id 1 is not used in any of the records in SYS_TABLESPage_id: 8, next page_id: 4294967295Record position: 65Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 8 50 3 2 0 0 0 0 0 Db/table: infimumSpace id: 1768842857 (0x696E6669)Next record at offset: 8DRecord position: 8DChecking field lengths for a row (SYS_TABLES): OFFSETS: 16 11 17 24 32 36 40 48 52 52 Db/table: SYS_FOREIGNSpace id: 0 (0x0)Next record at offset: D5Record position: D5Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 16 22 29 37 41 45 53 57 57 Db/table: SYS_FOREIGN_COLSSpace id: 0 (0x0)Next record at offset: 122Record position: 122Checking field lengths for a row (SYS_TABLES): OFFSETS: 16 12 18 25 33 37 41 49 53 53 Db/table: test/testibdSpace id: 2 (0x2)Updating test/testibd (table_id 17) with id 0x01000000SYS_TABLES is updated successfullyInitializing table definitions...Processing table: SYS_TABLES - total fields: 10 - nullable fields: 6 - minimum header size: 5 - minimum rec size: 21 - maximum rec size: 555Processing table: SYS_INDEXES - total fields: 9 - nullable fields: 5 - minimum header size: 5 - minimum rec size: 29 - maximum rec size: 165Setting SPACE=1 in SYS_INDEXES for TABLE_ID = 17Page_id: 11, next page_id: 4294967295Record position: 65Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 50 7 2 0 0 0 0 TABLE_ID: 3798561113125514496SPACE: 1768842857Next record at offset: 8CRecord position: 8CChecking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 35 39 43 47 TABLE_ID: 11SPACE: 0Next record at offset: CERecord position: CEChecking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 36 40 44 48 TABLE_ID: 11SPACE: 0Next record at offset: 111Record position: 111Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 36 40 44 48 TABLE_ID: 11SPACE: 0Next record at offset: 154Record position: 154Checking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 35 39 43 47 TABLE_ID: 12SPACE: 0Next record at offset: 22CRecord position: 22CChecking field lengths for a row (SYS_INDEXES): OFFSETS: 15 8 16 22 29 44 48 52 56 TABLE_ID: 17SPACE: 2Updating SPACE(0x00000001 , 0x01000000) for TABLE_ID: 17sizeof(s)=4Next record at offset: 74SYS_INDEXES is updated successfully

 

Step 7 : 使用percona recovery tool 重新checksum ibdata

重复执行以下命令,直到程序没有输出为止。

shell> /root/install/percona-data-recovery-tool-for-innodb-0.5/innochecksum -f /xfs/mysql3321/ibdata1

输出结果
page 8 invalid (fails old style checksum)page 8: old style: calculated = 0xF4AD74CB; recorded = 0xEECB309Dfixing old checksum of page 8page 8 invalid (fails new style checksum)page 8: new style: calculated = 0x6F0C29B4; recorded = 0x3D02308Cfixing new checksum of page 8page 11 invalid (fails old style checksum)page 11: old style: calculated = 0x3908087C; recorded = 0xF9E8D30Cfixing old checksum of page 11page 11 invalid (fails new style checksum)page 11: new style: calculated = 0xB26CFD77; recorded = 0xDB25D39Dfixing new checksum of page 11

 

Step 8 : 启动mysql服务

shell> service mysqld3321 start

 

参考文档:

http://www.chriscalender.com/?p=28

http://www.mysqlperformanceblog.com/2011/05/13/connecting-orphaned-ibd-files/

http://blogs.innodb.com/wp/2012/04/innodb-transportable-tablespaces/

 

 

 

bitsCN.com
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
雷电模拟器如何新建一个模拟器-雷电模拟器新建一个模拟器的方法雷电模拟器如何新建一个模拟器-雷电模拟器新建一个模拟器的方法Mar 05, 2024 pm 03:04 PM

最近一些刚刚下载接触雷电模拟器软件的用户,询问小编雷电模拟器如何新建一个模拟器?以下内容就带来了雷电模拟器新建一个模拟器的方法,让我们一起来下文看看吧。找到雷电模拟器器软件。双击打开雷电多开器。点击新建/复制模拟器。点击新建模拟器。就可以得到一个新建的模拟器了。找到雷电模拟器器软件,双击打开雷电多开器,点击新建/复制模拟器,点击新建模拟器,就可以得到一个新建的模拟器了。

如何在电脑上创建新的Word文档如何在电脑上创建新的Word文档Dec 27, 2023 pm 10:05 PM

新建word文档的方法也是有很多种的,我们可以通过右键桌面,然后点击新建doc文档还是docx文档,具体的方法都是差不多的,下面我们一起来看一下吧。使用电脑新建word文档方法:win11:1、首先我们右键点击“新建”。2、然后选择“docx或者是doc”文件。3、最后就可以完成创建了。win10:1、我们右键选择“新建”。2、随后还是选择两个文档中的一个。3、最后就完成创建了。win7:1、首先右键选择“新建”。2、然后选择word文档。3、最后就可以完成新建了。

解决Win10右键没有"新建"选项的问题解决Win10右键没有"新建"选项的问题Jan 05, 2024 am 09:45 AM

在使用win10系统的时候,有些小伙伴们在桌面使用鼠标右键的时候,发现右键菜单中没有新建的选项,其实只需要通过注册表往里面添加一个选项就能够右键新建了。win10右键没有新建选项怎么办:1、按下组合键+打开运行,输入点击确定,打开注册表编辑器。2、然后依次展开文件夹:。3、然后找到文件夹,如果没有该文件夹,就右键文件夹--,命名为。4、打开new文件夹中的文件后,我们将这个数值数据更改为。5、然后重启电脑,就能够解决这个问题了。

企业微信新建一个月报的详细方法企业微信新建一个月报的详细方法Mar 25, 2024 pm 05:36 PM

1、打开企业微信。2、点击下左侧的【应用】图标按钮。3、点击下【汇报】,【新建】,【月报】选项。4、然后可以看到,需要输入本月工作等。5、输入本月工作的内容,其他的可填可不填,点击【提交】按钮。6、最后就可以看到自己的月报详情了。

Win10磁盘新建跨区卷灰色怎么版Win10磁盘新建跨区卷灰色怎么版Jul 02, 2023 am 08:13 AM

Win10磁盘新建跨区卷灰色怎么办?有时候我们硬盘中有多个未使用的空间,我们可以将他们合并起来放在一个逻辑卷中,这样可以更有效地使用多个硬盘上的空间,这个就是跨区卷了。但是有网友说自己的win10系统在新建跨区卷的时候出现问题,发现磁盘新建跨区卷灰色点不了怎么回事?如何新建跨区卷?下面小编教下大家正确的新建跨区卷方法。  Win10磁盘新建跨区卷灰色解决步骤  首先,如下图所示两个硬盘上的空间可以使用同一个卷,建立跨区卷即可。  那么跨区卷灰色点不了的原因可能有下面的因素:  1、如果包含一个跨

如何实现MySQL中查看表的数据的语句?如何实现MySQL中查看表的数据的语句?Nov 08, 2023 pm 01:40 PM

标题:MySQL中查看表的数据的语句及具体代码示例MySQL是一种开源的关系型数据库管理系统,它被广泛应用于各种规模的应用程序中。在MySQL中,查看表的数据是一个非常基础的操作,下面将介绍如何通过具体的语句和代码示例实现这一操作。首先,我们将介绍通过MySQL命令行工具查看表的数据的语句及具体代码示例。假设我们有一个名为“employees”的表,以下是通

win11新建文档教程win11新建文档教程Dec 30, 2023 pm 07:59 PM

在win11中,我们可以通过新建文档的方式添加文章或记事本,但是有朋友不知道win11怎么新建文档,其实右键空白处就可以了。win11怎么新建文档:1、右键桌面或资源管理器空白处,选择“新建”2、接着在其中选择“文本文档”3、新建完成后,就可以看到自己新建的文本文档了。4、我们也可以选择“新建”一个“doc/docx文档”5、新建完成后,双击该文档就可以打开了。

真我手机文件夹建立步骤指南真我手机文件夹建立步骤指南Mar 23, 2024 pm 03:51 PM

真我手机文件夹建立步骤指南在日常生活中,我们使用手机来存储各种各样的文件,包括照片、视频、文档等等。然而,随着时间的推移,手机上的文件可能会越来越多,导致手机内存不足或文件难以管理。为了更好地整理文件并提高手机使用效率,手机文件夹的建立变得尤为重要。真我手机是一款受欢迎的智能手机品牌,拥有强大的系统和多样的功能。在真我手机上建立文件夹可以帮助用户更好地整理文

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),