1. Recover InnoDB dictionary

Recover InnoDB dictionary

MySQL table example

Why do we need to recover InnoDB dictionary

c_parser is a tool from TwinDB recovery toolkit that can read InnoDB page and fetch records out of it. Although it can scan any stream of bytes recovery quality is higher when you feed c_parser with pages that belong to the PRIMARY index of the table. All InnoDB indexes have their identifiers a.k.a. index_id. The InnoDB dictionary stores correspondence between table name and index_id. That would be reason number one.

Another reason – it is possible to recover table structure from the InnoDB dictionary. When a table is dropped MySQL deletes respective .frm file. If you had neither backups nor table schema it becomes quite a challenge to recover the table structure. This topic however deserves a separate post which I write some other day.

Let’s assume you’re convinced enough and we can proceed with InnoDB dictionary recovery.

Compiling TwinDB recovery toolkit

The source code of the toolkit is hosted on GitHub. You will need git to get the latest revision, so make sure you have it:

Get the latest revision of the toolkit:

As prerequisites we would need gcc, flex and bison. Check that you have them:

Good. Now let’s compile the code:

If there are no errors we are ready to proceed.

Splitting ibdata1

The InnoDB dictionary is stored in ibdata1. So we need to parse it and get pages that store records of the dictionary. stream_parser does it.

stream_parser finds InnoDB pages in ibdata1 and stores them sorted by page type(FIL_PAGE_INDEX or FIL_PAGE_TYPE_BLOB) by index_id.
Here’s the indexes:

SYS_TABLES

SYS_INDEXES

SYS_COLUMNS

and SYS_FIELDS

As you can see the dictionary is pretty small, just one page per index.

Dumping records from SYS_TABLES and SYS_INDEXES

To fetch records out of the index pages you need c_parser. But first, let’s create directory for dumps

InnoDB dictionary is always in REDUNDANT format, so options -4 is mandatory:

Here’s our sakila tables:

dumps/default/SYS_TABLES is a dump of the table eligible for LOAD DATA INFILE command. The exact command c_parsers prints to standard error output. I saved it in dumps/default/SYS_TABLES.sql

The same way let’s dump SYS_INDEXES:

Make sure we have sane result in the dumps

Now we can work with the dictionary, but it’s more convenient if the tables are in MySQL.

Loading dictionary tables into MySQL

The main usage of SYS_TABLES and SYS_INDEXES is to get index_id by table name. It’s possible to run two greps. Having SYS_TABLES and SYS_INDEXES in MySQL makes job easier.

Before we can process let’s make sure mysql user can read from the root’s home directory. Maybe it’s not wise from security standpoint. If it’s your concern create whole recovery environment somewhere in /tmp.

Create empty dictionary tables in some database(e.g. test)

And load the dumps:

Now we have the InnoDB dictionary in MySQL and we can query it as any other MySQL table:

Here we can see that sakila.actor has two indexes: PRIMARY and idx_actor_last_name. Respective index_id are 1828 and 1829.

Stay tuned to learn what to do with them and how to recover sakila.actor

Have a question? Ask the experts!

Previous Post Next Post
  • UPDATE (01/01/2017):

    We stopped further development of undrop-for-innodb and do not support its open source versions.