MySQL传输表空间

MySQL 5.6开始可以把一个表从一个数据库迁移到另一个数据库或者机器上,方便于数据迁移。
传输表空间要求:
1、MySQL 5.6或以上版本
2、innodb_file_per_table是开启状态,即使用独立表空间方式
3、源端与目标端pagesize一致
4、表在传输时该表为只读状态

例:将ray.ray_t数据迁移至lei用户下

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lei                |
| mysql              |
| performance_schema |
| ray                |
| sys                |
+--------------------+
6 rows in set (0.00 sec)
mysql> select count() from ray.ray_t;
+----------+
| count() |
+----------+
|   262144 |
+----------+
1 row in set (0.06 sec)
mysql> select count(*) from lei.ray_t;
ERROR 1146 (42S02): Table 'lei.ray_t' doesn't exist

目标端创建表
在lei下创建跟ray.ray_t一模一样的表

mysql> show create table ray.ray_t;
+-------+------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                   |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------+
| ray_t | CREATE TABLE ray_t (
id int(11) DEFAULT NULL,
KEY ray_t_id (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> use lei;
Database changed
mysql> CREATE TABLE ray_t (
->   id int(11) DEFAULT NULL,
->   KEY ray_t_id (id)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Query OK, 0 rows affected (0.00 sec)
mysql> select count() from lei.ray_t;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.01 sec)

目标端表卸载表空间(lei.ray_t表空间卸载)

mysql> use lei
Database changed
mysql> alter table ray_t discard tablespace;
Query OK, 0 rows affected (0.00 sec)

源端表空间导出

mysql> use ray
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> flush table ray.ray_t for export;
Query OK, 0 rows affected (0.00 sec)

操作系统层复制文件至目标端

[root@ray1 ray]# cp ray_t.ibd ray_t.cfg /mysqldata/my3306/data/lei/
[root@ray1 ray]# chown -R mysql:mysql /mysqldata/my3306/data/lei/

源端解锁表

mysql> use ray;
Database changed
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

目标端表空间导入

mysql> use lei;
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> alter table lei.ray_t import tablespace;
Query OK, 0 rows affected (0.06 sec)

mysql> select count() from lei.ray_t;
+----------+
| count(*) |
+----------+
|   262144 |
+----------+
1 row in set (0.08 sec)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值