innodb_file_per_table, then you have a separate .ibd file for each InnoDB table.
Now, you have your running database with a bunch of tables, and you want to replace some of them with the backup .ibd files. According to the MySQL docs, you'd do this:
ALTER TABLE foo DISCARD TABLESPACE;(this deletes the current .ibd file)
- copy the old .ibd file into your database directory
ALTER TABLE foo IMPORT TABLESPACE;
foouses partitions, ie, its create statement was something like this:
CREATE TABLE foo ( ... ) PARTITION BY ... ( PARTITION p0 ..., );In this case, you cannot discard the tablespace, and the first alter command throws an error:
mysql> ALTER TABLE foo DISCARD TABLESPACE; ERROR 1031 (HY000): Table storage engine for 'foo' doesn't have this optionI have not investigated if there are workarounds for this, but I do have a little more information on what's happening. Remember that each .ibd file is a tablespace. For a partitioned table, there are multiple .ibd files, one for each partition. The table's files look like this:
foo.frm foo.par foo#P#p0.ibd foo#P#p1.ibd ...Where
p1, etc. are the partition names that you specified in the create statement. Each partition is a different tablespace and has its own tablespace id. When you create an InnoDB table without partitioning, the internal tablespace id counter is incremented by 1. When you create an InnoDB table with paritions, the internal tablespace id counter is incremented by the number of partitions. The actual tablespace id is stored in each partition's .ibd file somewhere within the first 100 bytes. I have not attempted to find out where exactly though.