版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xxzhaobb/article/details/84068471
源库 test
目标库 tes
把test库下的 t3表 ,传输到tes库下面
步骤
1 目标库上建立与原库一样的表t3
2 卸载目标库下的t3的表空间
3 在源库执行表空间导出
4 将源库上的导出文件复制到目标库,并修改权限
5 源库上执行解锁操作
6 目标库上执行表空间导入
-- 源库,test下的t3表
mysql> select * from t3;
+------+-------+------+
| year | month | day |
+------+-------+------+
| 2018 | 1 | 1 |
| 2018 | 1 | 2 |
| 2018 | 1 | 3 |
| 2018 | 1 | 4 |
| 2018 | 1 | 5 |
+------+-------+------+
5 rows in set (0.00 sec)
mysql> select database();
+------------+
| database() |
+------------+
| test |
+------------+
1 row in set (0.00 sec)
mysql>
--目标库tes下,创建与源库一样的表t3
use tes;
create table t3(year int,month int,day int);
-- 卸载目标库tes下t3表的表空间,然后发现 tes库下面的t3.idb不见了
use tes;
alter table t3 discard tablespace;
mysql> alter table t3 discard tablespace;
Query OK, 0 rows affected (0.01 sec)
mysql>
[root@test tes]# ls t3*
t3.frm t3.ibd
[root@test tes]# ls t3*
t3.frm
[root@test tes]#
-- 然后在源库test执行表空间导出操作
use test;
flush table t3 for export;
mysql> select database();
+------------+
| database() |
+------------+
| test |
+------------+
1 row in set (0.00 sec)
mysql> flush table t3 for export;
Query OK, 0 rows affected (0.00 sec)
mysql>
-- 导出后,会发现源库test下多了一个t3.cfg文件
[root@test test]# ls t3*
t3.cfg t3.frm t3.ibd
[root@test test]#
-- 将源库test下的t3.ibd和t3.cfg文件复制到目标库tes下并修改权限
[root@test test]# cp t3.cfg ../tes/
[root@test test]# cp t3.ibd ../tes/
[root@test tes]# ls -l t3.*
-rw-r-----. 1 root root 481 Nov 14 11:19 t3.cfg
-rw-rw----. 1 mysql mysql 8620 Nov 14 11:08 t3.frm
-rw-r-----. 1 root root 98304 Nov 14 11:19 t3.ibd
[root@test tes]#
[root@test tes]# ls -l t3.*
-rw-rw----. 1 mysql mysql 481 Nov 14 11:19 t3.cfg
-rw-rw----. 1 mysql mysql 8620 Nov 14 11:08 t3.frm
-rw-rw----. 1 mysql mysql 98304 Nov 14 11:19 t3.ibd
[root@test tes]#
-- 将源库test 执行解锁操作
unlock tables;
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
mysql>
-- 在目标库,执行表空间导入操作
alter table t3 import tablespace;
mysql> use tes;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from t3;
ERROR 1814 (HY000): Tablespace has been discarded for table 't3'
mysql> select database();
+------------+
| database() |
+------------+
| tes |
+------------+
1 row in set (0.00 sec)
mysql> alter table t3 import tablespace;
Query OK, 0 rows affected (0.18 sec)
mysql> select * from t3;
+------+-------+------+
| year | month | day |
+------+-------+------+
| 2018 | 1 | 1 |
| 2018 | 1 | 2 |
| 2018 | 1 | 3 |
| 2018 | 1 | 4 |
| 2018 | 1 | 5 |
+------+-------+------+
5 rows in set (0.00 sec)
mysql>
END