MySQL 大表迁移

一、需求分析

线上100G 大表 table1 迁移,从DB1 迁移到DB2。

二、环境要求:

1.MySQL 使用InnoDB 存储引擎,且开启独立表空间;

2.两个库的MySQL版本一致(未做不同版本测试)。

三、操作详情:

1.导出DB1 中table1 的表结构SQL到DB2中;

2.卸载DB2 中table1 的表空间;

alter table table1 discard tablespace;

如果是卸载DB1整个库可以这样操作:

SELECT CONCAT('ALTER TABLE ', TABLE_NAME, ' discard tablespace;') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'DB2' and TABLE_TYPE like '%TABLE%' ;

把这条语句查询结果导出为sql文件,然后在 DB2 中执行这个sql文件,执行完毕则使 DB2 库所有表空间已卸载;
3.复制DB1原表的物理文件table.ibd到DB2中,修改属主属组
chown -R mysql.mysql /dest/dir/table.ibd
 
4.在DB2重新装载table1 的tablespace;
alter table table1 import tablespace;
 
 
root@localhost 17:18:  [test]> alter table table1 import tablespace;
Query OK, 0 rows affected, 1 warning (0.08 sec)

root@localhost 17:18:  [test]> show warnings;
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                                      |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1810 | InnoDB: IO Read error: (2, No such file or directory) Error opening './test/sc_akucun_consume_copy1.cfg', will attempt to import without schema verification |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 

猜你喜欢

转载自www.cnblogs.com/Camiluo/p/10702018.html