mysql ERROR 1050 (42S01): Table already exists

At the time of database startup, I accidentally deleted the data file, and then I kept working on this table and kept reporting errors. The query report did not exist, but a new table with the same name already existed. The solution is to create a table with the same name in another database and copy its data files.
mysql> show databases;
+ — — — — — — — — — — — — — — — — — — — — +
| Database |
+ — — — — — — — — — — — — — — — — — — — — +
| information_schema |
| mysql |
| performance_schema |
| test |
+——————–+
mysql> use test
mysql> create table t1(id int);
ERROR 1813 (HY000): Tablespace for table ‘`test`.`t1`’ exists. Please DISCARD the tablespace before IMPORT.
mysql> alter table t1 DISCARD tablespace;
ERROR 1146 (42S02): Table ‘test.t1’ doesn’t exist

mysql> create database gg;
mysql> show databases;
+ — — — — — — — — — — — — — — — — — — — — +
| Database |
+ — — — — — — — — — — — — — — — — — — — — +
| information_schema |
| gg |
| mysql |
| performance_schema |
| test
| + — — — — — — — — — — — — — — — — — — — — +
mysql> use gg
Database changed
mysql> create table t1(id int);

go to the database gg
cp-a t1.frm.. /test/t1.frm

mysql> select * from t1;
ERROR 1146 (42S02): Table ‘test.t1’ doesn’t exist
mysql> Alter TABLE T1, TABLESPACE;
Query OK, 0 rows affected, 2 warnings (0.01 SEC)

goes to database gg
cp -a t1.ibd .. /test/t1.ibd
mysql> use test
mysql> select * from t1;
ERROR 1814 (HY000): Tablespace has been discarded for table ‘t1’
mysql> Alter TABLE T1 Import TABLESpace;
Query OK, 0 rows affected, 1 warning (0.04 SEC)
mysql> select * from t1;
Empty set (0.00 SEC)

Read More: