Restore corrupted innodb from .frm and .ibd files

Sql comes in many different,  for some flavours, if the db crashes, updated or anything is changed within it.
You can simply move the files in the directory of your new sql db and it should read it instantly.
With innodb ,
it does read them but when you try to SELECT from the tables,
it returns TABLE does not exist.
First install mysqlfrm which we will use to read the tables form.
sudo apt-get install mysql-utilities
Next do mysqlfrm --user=mysql --server=root:maria@localhost --port=3308 sql_table.frm
You can change the variables with the ones specific to your server of course.
The output of this will be a command that you can use to create a table of the same form.
Create a new db of a name that you desire, 
then copy the output of mysqlfrm and execute it to create a table inside our newly created db.
Now that a table of the same form is created,
Execute those commands
ALTER TABLE 'sql_table' ROW_FORMAT=DYNAMIC;
ALTER TABLE sql_table DISCARD TABLESPACE;
Next copy your own .frm and .ibd files inside the mysql database, for my case it was in /var/lib/mysql/dbname
then execute ALTER TABLE sql_table IMPORT TABLESPACE;
And everything should be well!.

Comments

Popular posts from this blog

Create a route optimization algorithm with zero costs using google's OR-tools and OSRM Part 3

Learn python programming through algorithms - Binpacking part 2

Create a route optimization algorithm with zero costs using google's OR-tools and OSRM Part 1