(步骤:建表, 禁用表空间,复制表空间,重用表空间)
mysql> desc test;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(20) | NO | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> use move_test;
Database changed
mysql> create table test(id int not null primary key,name varchar(20) not null) ;
mysql> system cp /mnt/data/mysql/data/reading/test.ibd /mnt/data/mysql/data/move_test/
mysql> system chown -R mysql:mysql /mnt/data/mysql/data/move_test/test.idb
mysql> alter table test import tablespace;
Query OK, 0 rows affected, 1 warning (0.12 sec)
mysql> select database();
+------------+
| database() |
+------------+
| move_test |
+------------+
1 row in set (0.00 sec)
mysql> select * from test;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)