表空间移植技术

表空间迁移技术:实现表快速迁移

1.  停止相关业务

mysql> lock tables t100w read;

mysql> delete from t100w where id=1000;

ERROR 1099 (HY000): Table 't100w' was locked with a READ lock and can't be updated

mysql> select * from t100w limit 10;

可查不可DML

2. 目标库创建一摸一样的表

mysql> create database test  charset utf8mb4;

Query OK, 1 row affected (0.01 sec)

mysql> use test;

mysql>  CREATE TABLE `t100w` (

    ->  `id` int(11) NOT NULL,

    ->  `num` int(11) DEFAULT NULL,

    ->  `k1` char(2) DEFAULT NULL,

    ->  `k2` char(4) DEFAULT NULL,

    ->  `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

    ->  PRIMARY KEY (`id`),

    ->  KEY `idx` (`k1`,`k2`)

    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;

3. 将目标空的ibd表空间删除

mysql> alter table t100w discard tablespace;

4. 迁移ibd至目标库

[root@db01 test]# cp /data/3306/data/test/t100w.ibd /data/3307/data/test/

[root@db01 test]# chown -R mysql.mysql /data

5. 导入表空间

mysql> alter table t100w import tablespace;

6. 解锁业务

mysql> unlock tables ;

你可能感兴趣的:(表空间移植技术)