Mysql - Restore Table From .FRM and .Ibd File - Database Administrators Stack Exchange
Mysql - Restore Table From .FRM and .Ibd File - Database Administrators Stack Exchange
I have previously saved a copy of /var/lib/mysql/ddms directory ("ddms" is the schema name).
Now I installed a new MySQL on a freshly installed Ubuntu 10.04.3 LTS by running apt-get
48 install mysql-server , I believe version 5.1 was installed. After I copy the ddms directory under
/var/lib/mysql, some of its tables work fine, these are the tables with an associated set of three
files: a .frm file, a .MYD file and a .MYI file.
However, there are two tables with a different set of files: a .frm file and a .ibd file. These two
tables didn't show up in the table list in phpMyAdmin. When I look at the error log, it says:
mysql innodb
Share Improve this question edited Jan 6, 2017 at 20:48 asked Apr 22, 2012 at 3:59
Follow T.Todua Tong Wang
184 2 14 583 1 5 5
You certainly cannot upgrade to 8.0 without first getting t 5.7. What versions are involved? – Rick James
Sep 1, 2022 at 18:38
Sorted by:
10 Answers
Highest score (default)
InnoDB tables cannot be copied the same way that MyISAM tables can.
52 Just copying the .frm and .ibd files from one location to another is asking for trouble. Copying
the .frm and .ibd file of an InnoDB table is only good if and only if you can guarantee that
the tablespace id of the .ibd file matches exactly with the tablespace id entry in the
metdata of the ibdata1 file.
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 1/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
Here is excellent link on how to reattach any .ibd file to ibdata1 in the event of mismatched
tablespace ids : http://www.chriscalender.com/?tag=innodb-error-tablespace-id-in-file. After
reading this, you should come to the immediate realization that copying .ibd files is just plain
crazy.
You could apply the suggestions from the Chris Calendar link, or you could go back to the old
installation of mysql, startup up mysql, and then mysqldump the ddms database. Then, import
that mysqldump into your new mysql instance. Trust me, this would be far easier.
Share Improve this answer Follow edited Jan 30, 2019 at 15:20 answered Apr 23, 2012 at 19:33
Phillip RolandoMySQLDBA
5 3 179k 32 309 509
I recently experienced this same issue. Here are the steps I used to solve it without having to
mess around with the tablespace id as RolandoMySQLDBA mentions above. I'm on a Mac and
22 so I used MAMP in order to restore the Database to a point where I could export it in a MySQL
dump.
You can read the full blog post about it here: http://www.quora.com/Jordan-Ryan/Web-
Dev/How-to-Recover-innoDB-MySQL-files-using-MAMP-on-a-Mac
-ibdata1
-ib_logfile0
-ib_logfile1
-Fresh installation of MAMP / MAMP Pro that you are willing to destroy (if need be)
1. SSH into your web server (dev, production, no difference) and browse to your mysql
folder (mine was at /var/lib/mysql for a Plesk installation on Linux)
3. Download an archive of mysql folder which should contain all mySQL databases, whether
MyISAM or innoDB (you can scp this file, or move this to a downloadable directory, if
need be)
5. Browse to /Applications/MAMP/db/mysql/
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 2/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
7. Copy in all folders and files included in the archive of the mysql folder from the
production server (mt Plesk environment in my case) EXCEPT DO NOT OVERWRITE:
-/Applications/MAMP/db/mysql/mysql/
-/Applications/MAMP/db/mysql/mysql_upgrade_info
-/Applications/MAMP/db/mysql/performance_schema
8. And voila, you now should be able to access the databases from phpMyAdmin, what a
relief!
But we're not done, you now need to perform a mysqldump in order to restore these files to
your production environment, and the phpmyadmin interface times out for large databases.
Follow the steps here:
http://nickhardeman.com/308/export-import-large-database-using-mamp-with-terminal/
Copied below for reference. Note that on a default MAMP installation, the password is "root".
Step Two: Navigate to the MAMP install by entering the following line in terminal cd
/applications/MAMP/library/bin Hit the enter key
Step Three: Write the dump command ./mysqldump -u [USERNAME] -p [DATA_BASENAME] >
[PATH_TO_FILE] Hit the enter key
Example:
Quick tip: to navigate to a folder quickly you can drag the folder into the terminal window and
it will write the location of the folder. It was a great day when someone showed me this.
Step Four: This line of text should appear after you hit enter Enter password: So guess what,
type your password, keep in mind that the letters will not appear, but they are there Hit the
enter key
Step Five: Check the location of where you stored your file, if it is there, SUCCESS Now you
can import the database, which will be outlined next.
Now that you have an export of your mysql database you can import it on the production
environment.
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 3/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
Share Improve this answer Follow answered May 23, 2013 at 17:18
Jordan Ryan
321 3 4
1 Still working as of 2018. This answer is gold. The important part to me is the #7, those are the files you
absolutely got to keep (it's not mentioned anywhere else on similar solutions, thanks for that @jordan).
– Maen May 29, 2018 at 0:24
@Bigood glad it's still helping! – Jordan Ryan Nov 26, 2018 at 8:24
getting error 1146 table doesn't exist when doing the dump – Robert Sinclair Nov 20, 2019 at 2:24
You can also use PHPMyAdmin to do the export (instead of mysqldump from Termina). – Paul Schreiber
May 9, 2020 at 17:21
I have recovered my MySQL 5.5 *.ibd and *.frm files with using MySQL Utilites and MariaDB
10.
21
1) Generating Create SQLs.
You can get your create sql's from frm file. You must use :
https://downloads.mysql.com/archives/utilities/
Share Improve this answer Follow edited Jun 1, 2020 at 7:45 answered Jan 30, 2016 at 17:02
Jahirul Islam Mamun Ecd
123 3 311 2 4
1 This worked for me. Although mysqlfrm (tried versions 1.3.5 and 1.6.5 with MySQLs 5.6 and 5.7) didn't
give correct CREATE definition, even when using MySQL 5.7 (the default ROW_FORMAT changed in
MySQL 5.7.9) resulting in Schema mismatch (Expected FSP_SPACE_FLAGS=0x21, .ibd file contains
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 4/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
0x0.) when importing the tablespace. Manually adding ROW_FORMAT=compact at the end of the
CREATE statement did the trick. – Jānis Elmeris Jul 26, 2017 at 11:30
@JānisElmeris > Manually adding ROW_FORMAT=compact at the end of the CREATE statement did
the trick. That worked for me too. Thanks! 👍 – Synetech Oct 12, 2019 at 14:52
You sir, are a life-saver. That got error -1 threatened to cause me a big data loss. – Ben Hillier Sep 12,
2020 at 16:29
I've had the exact same problem only having the files as backup.
4 What i did to solve it was to copy the database files into /var/lib/mysql/yourdb and the
ibdata1 which is placed in /var/lib/mysql.
I was then able to verify that i could access the tables mysql -u root -p dbname and the
querying some of the tables that were previous corrupted.
Share Improve this answer Follow answered Aug 24, 2014 at 19:38
Tue
41 1
If you are using MAMP and you cannot get MySQL to start after you copy your files over, I put
innodb_force_recovery = 2 inside my.ini and then I was able to get mysql to launch and
3 export my db out.
Share Improve this answer Follow edited Jan 9, 2017 at 16:44 answered Oct 5, 2016 at 5:28
T.Todua Peter Wakeman
184 2 14 31 1
Note: Try to install MySQL same version, if your crashed MySQL version was 5.6, please
install MySQL 5.6. ( brew install [email protected] ). If following process fails try the same things
2 with MariaDB. (In my case, by MariaDB, I get back all database)
Process 1
Before start, must stop MySQL or MariaDB. Use this command ( brew services stop mysql ),
For MariaDB brew services stop mariadb
ibdata1 file copy from backup mysql folder and paste and replace it inside new installed
mysql folder's ibdata1 (usr/local/var/mysql) or mamp/xampp mysql folder location.
ib_logfile0 and ib_logfile1 no need to replace first. If above process don't work, copy this
file from backup mysql folder and replace. (In my case, i did not replace)
Now copy 1 database for test (for example : testdb) from backup mysql folder and paste
it inside new installed mysql folder. In testdb must have .frm and .ibd file.
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 5/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
Restart mysql/mariadb (brew services start mysql) or (brew services start mariadb)
USE testdb;
SHOW TABLES;
Process 2
Open testdb.sql in notepad/sublime you will see all database table schema but not data.
Create new database "newtestdb" and run the command >> mysqldump -uroot -p --
databases newtestdb > testdb.sql
It should create all database tables, Now if you check inside "newtestdb" you will see .frm
and .ibd file.
Run this command one by one for all table, ALTER TABLE tablename DISCARD TABLESPACE; if
you check newtestbd .ibd file will disapear.
Now Copy only .ibd file from backup database testdb folder and paste it in newtestdb.
Share Improve this answer Follow edited Jun 1, 2020 at 6:19 answered May 31, 2020 at 15:53
Jahirul Islam Mamun
123 3
If you're able to restore the the *.ibd file to the original MySQL server, don't forget to restore
the file access rights too. In my case (MySQL8 on CentOS7), I restored file to
1 /var/lib/mysql/db/tablename.ibd and run:
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 6/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
Before fixing access rights, accessing the table resulted in error "2006 MySQL server has gone
away". After fixing access rights, the table worked (even without restart of mysqld service).
I just want to add one more thing for macos El Capitan users. MySQL utilities is not supported
for this version, so mysqlfrm command is not helpful. What I did is recovering my table
1 structures with dbsake as shown in this link:
https://www.percona.com/blog/2015/12/16/recovering-table-structure-from-frm-files-using-
dbsake/
then use frmdump command and provide path to your .frm file:
you will get the create statement. Once I've done this, I simply followed the steps 2 to 5
already mentioned by @Ecd. Hope it helps someone.
Share Improve this answer Follow answered May 21, 2019 at 0:59
user2804064
215 2 7
(At first, you will need to install in your OS, the small package named "mysql-utilities" and use
mysqlfrm --port=3333 your_table.frm > result.sql --basedir=/path/to/your/installation-
1 folder/mysql to restore table-creation sql), after that, I've collected posts from the similar
topics, which weren't mentioned in this topic:
solution 0: https://dba.stackexchange.com/a/57157/44247
solution 1: https://dba.stackexchange.com/a/59978
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 7/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
solution 4: Recover MySQL database from data folder without ibdata1 from ibd files
solution 5: https://dba.stackexchange.com/a/159001
solution 6: https://dba.stackexchange.com/a/144573
Share Improve this answer Follow edited Aug 23, 2021 at 6:36 answered Jan 6, 2017 at 17:47
T.Todua
184 2 14
0 1.- I had a backup of the base a few months ago this helped me to lift this backup in xampp in
Windows 10 and create the tables to have the structure (configuration: Windows 10, xampp-
windows-x64-7.1.30-5-VC14) mysql my.ini configuration file at the end
NOTE: Some tables did not have ROW_FORMAT = COMPACT, so I went to operations on each
table and changed it manually.
(If I did not do that, an error appeared and I did not let the import).
NOTE2: I had the backup of months ago but it should also work by first recovering
the structure of the .frm files in case of not having a backup at hand.
(You can try this link:
https://www.percona.com/blog/2014/01/02/recover-table-structure-frm-files-mysql-
utilities/)
2.- Having the old database up, I proceeded to execute alter table xxx discard tablespace for
each table in the database that I wanted to recover, then the .ibd files of the data folder in C: /
xampp / mysql / data / system had been deleted (in this case it is this path)
3.- I proceeded to copy the .ibd files from the database I wanted to recover to the xampp
folder of the old database
4.- Having the files copied, run: alter table xxx import tablespace For each table in the
database, a warning will appear but we will ignore it, the data will be loaded in the table and
can be exported later.
5.- Export the entire database into an sql file and proceed to build it in production and
success!
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 8/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
# If you want to know which options a program supports, run the program
# with the "--help" option.
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 9/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 10/11
15/04/23, 12:37 mysql - restore table from .frm and .ibd file? - Database Administrators Stack Exchange
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 600
## UTF 8 Settings
#init-connect=\'SET NAMES utf8\'
#collation_server=utf8_unicode_ci
#character_set_server=utf8
#skip-character-set-client-handshake
#character_sets-dir="C:/xampp/mysql/share/charsets"
sql_mode=NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_ENGINE_SUBSTITUTION
log_bin_trust_function_creators = 1
[mysqldump]
quick
max_allowed_packet = 160M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
https://dba.stackexchange.com/questions/16875/restore-table-from-frm-and-ibd-file 11/11