一、需求分析
線上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)
