Recover MySQL table structures from FRM and IBD files only
Question:
Users often encounter situations where they need to restore a database but can only access the FRM and IBD files.
Can the table structure be restored?
Yes, table structure can be restored from FRM file even without IB_LOG file.
Steps:
1. Extract SQL creation statement from FRM file:
mysqlfrm --diagnostic
command to generate SQL create statements for each FRM file. <code class="language-sql">CREATE TABLE `example_table` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(150) NOT NULL, `photo_url` varchar(150) NOT NULL, `password` varchar(600) NOT NULL, `active` smallint(6) NOT NULL, `plan` int(11) NOT NULL, PRIMARY KEY `PRIMARY` (`id`) ) ENGINE=InnoDB;</code>
2. Use SQL statements to create tables:
3. Recover data:
<code class="language-sql">ALTER TABLE example_table DISCARD TABLESPACE;</code>
<code class="language-bash">cp backup/example_table.ibd /path/to/example_table.idb</code>
<code class="language-sql">ALTER TABLE example_table IMPORT TABLESPACE;</code>
The above is the detailed content of Can We Recover MySQL Table Structure from FRM and IBD Files Only?. For more information, please follow other related articles on the PHP Chinese website!