Bug #100797 after restert DB, alter table t import tablespace fail
Submitted: 10 Sep 2020 11:37 Modified: 28 Sep 2020 14:52
Reporter: aceking king Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:mysql-8.0.21 OS:Linux
Assigned to: MySQL Verification Team CPU Architecture:Any

[10 Sep 2020 11:37] aceking king
Description:
1. alter table t discard tablespace;
2. shutdown server
3. start server, then mv ibd file to t.ibd
4. alter table t import tablespace; cause  ERROR 1034 (HY000): Incorrect key file for table 't'; try to repair it

How to repeat:
#  mysql-test file
create table t (a bigint primary key, b varchar(100));
insert into t values(1,2),(3,4), (5,6);
flush tables;
-- let $MYSQLD_DATADIR= `select @@datadir`
-- copy_file $MYSQLD_DATADIR/test/t.ibd  $MYSQLD_DATADIR/test/t2.ibd 
alter table t discard tablespace;

--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
-- send_shutdown
--source include/wait_until_disconnected.inc
--exec echo "restart:" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--enable_reconnect
--source include/wait_until_connected_again.inc
--disable_reconnect

-- copy_file $MYSQLD_DATADIR/test/t2.ibd  $MYSQLD_DATADIR/test/t.ibd 
alter table t import tablespace;

Suggested fix:
[28 Sep 2020 14:52] MySQL Verification Team
Hi,

This is not a bug, you are not following the procedure properly.

CREATE TABLE t1 (c1 INT) ENGINE=INNODB;
ALTER TABLE t1 DISCARD TABLESPACE;
FLUSH TABLES t1 FOR EXPORT; -- this you missed
shell> cp t1.ibd t2.ibd
shell> cp t1.cfg t2.cfg # you missed the .cfg file too
UNLOCK TABLES; -- this deletes the cfg file
...

all best
Bogdan