实践:mariadb进行表空间传输

需求:将源库中的表迁移到目标库中,通过传输表空间方式。

这个操作比导入导出方便多了。

环境:

MariaDB [lixf]> select version();
+---------------------+
| version()           |
+---------------------+
| 10.0.13-MariaDB-log |
+---------------------+
1 row in set (0.01 sec)


下面为具体的操作步骤:


传输表空间,针对于innodb:
在源库上创建表如在test库中创建lixf22:
MariaDB [test]> create table lixf22(id int);
Query OK, 0 rows affected (0.02 sec)

MariaDB [test]> insert into lixf22 values(11);
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> insert into lixf22 values(11);
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> insert into lixf22 values(11);
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> insert into lixf22 values(11);
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> select * from lixf22;
+------+
| id   |
+------+
|   11 |
|   11 |
|   11 |
|   11 |
+------+
4 rows in set (0.00 sec)

MariaDB [test]> flush table lixf22 for export;
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> unlock tables;
Query OK, 0 rows affected (0.01 sec)

下面为日志信息,注意export会生成.cfg文件。
141214 14:38:46 [Note] InnoDB: Sync to disk of '"test"."lixf22"' started.
141214 14:38:46 [Note] InnoDB: Stopping purge
141214 14:38:46 [Note] InnoDB: Writing table metadata to './test/lixf22.cfg'
141214 14:38:46 [Note] InnoDB: Table '"test"."lixf22"' flushed to disk
141214 14:39:05 [Note] InnoDB: Deleting the meta-data file './test/lixf22.cfg'
141214 14:39:05 [Note] InnoDB: Resuming purge




在新库上如lixf中,创建需要导入的表lixf22的表结构信息。
MariaDB [lixf]>  create table lixf22(id int);
Query OK, 0 rows affected (0.02 sec)

MariaDB [lixf]> alter table lixf22 discard tablespace;      #######这步比较关键
Query OK, 0 rows affected (0.01 sec)


#######导入表空间
MariaDB [lixf]> alter table lixf22 import tablespace;
Query OK, 0 rows affected (0.04 sec)

MariaDB [lixf]>

####下面可以查询lixf22表中的信息了。
MariaDB [lixf]> select * from lixf22;
+------+
| id   |
+------+
|   11 |
|   11 |
|   11 |
|   11 |
+------+


下面为日志信息,

141214 14:40:13 [Note] InnoDB: Importing tablespace for table 'test/lixf22' that was exported from host 'mysql2'
141214 14:40:13 [Note] InnoDB: Phase I - Update all pages
141214 14:40:13 [Note] InnoDB: Sync to disk
141214 14:40:13 [Note] InnoDB: Sync to disk - done!
141214 14:40:13 [Note] InnoDB: Phase III - Flush changes to disk
141214 14:40:13 [Note] InnoDB: Phase IV - Flush complete


mysql 5.6新版本也具有上面的功能,具体大家可能测试一下。

Chapter 14 Storage Engines




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值