Restore MySql Database From Just frm and idb File
There are situations where a MySQL server crashes or a hosting environment is decommissioned, leaving you with only the raw data directory files — specifically the .frm (table structure) and .ibd (InnoDB data) files — and no SQL dump to restore from.
This guide walks through recovering a MySQL database using only those files, using a utility called dbsake to extract the schema and MySQL's tablespace import feature to restore the data.
Step 1: Install the dbsake Tool
dbsake is a MySQL utility that can read .frm files and generate the original CREATE TABLE statements without a running MySQL server.
curl -s http://get.dbsake.net > dbsake
chmod u+x dbsake
./dbsake --version
Step 2: Extract the Table Schema from the .frm File
Use dbsake's frmdump command to read the .frm file and output the table definition:
./dbsake frmdump /PATH_TO_FRM/table_name.frm
This produces output similar to:
CREATE TABLE `table_name` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`created_at` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Copy this output. If you are migrating between MySQL versions (for example, from MySQL 5.6 to 5.7 or 8.0), add ROW_FORMAT=COMPACT to the table definition to avoid compatibility issues during import.
Step 3: Create the Table in MySQL
Connect to your MySQL server and create a new database, then run the CREATE TABLE statement extracted in the previous step:
CREATE DATABASE recovered_db;
USE recovered_db;
CREATE TABLE `table_name` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`created_at` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
This creates the table structure and generates a fresh .ibd file in the MySQL data directory.
Step 4: Discard the Empty Tablespace
Before importing the recovered data file, discard the empty tablespace MySQL just created:
ALTER TABLE table_name DISCARD TABLESPACE;
This removes the newly created .ibd file, making room for the recovered one.
Step 5: Copy the Recovered .ibd File
Copy your recovered .ibd file into the MySQL data directory for the new database:
cp /PATH_TO_RECOVERED/table_name.ibd /var/lib/mysql/recovered_db/table_name.ibd
Make sure the file permissions are correct so MySQL can read it:
chown mysql:mysql /var/lib/mysql/recovered_db/table_name.ibd
Step 6: Import the Tablespace
Import the recovered .ibd file into the table:
ALTER TABLE table_name IMPORT TABLESPACE;
If successful, MySQL will read the file and make the data accessible. You can now query the table and verify the recovered rows.
Notes
- This technique works with InnoDB tables (
.ibdfiles). MyISAM tables use different file formats (.MYD,.MYI) and require a different recovery approach. - The MySQL version on the recovery server should ideally match the original server version. Mismatches can cause tablespace import errors.
- If you receive an error like
Schema mismatchduring import, double-check that theCREATE TABLEstatement exactly matches the original schema, including character sets and row formats. - dbsake reads the binary
.frmformat reliably across MySQL versions, making it the most practical tool for this recovery scenario.
Conclusion
Losing a SQL dump is not the end of a database. As long as the InnoDB data files are intact, dbsake and MySQL's tablespace import mechanism give you a reliable path to full recovery. The process is straightforward: extract the schema from the .frm file, recreate the table structure, and import the original data file.