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)

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM