INNODB表快速迁移
本實驗在一臺server上啟動了2個mysql實例端口分別是3307?? 3308,目的是將3307的表aaa遷移到3308中去,并打開3308的slave
?
1.在3308上
mysql> drop table aaa;?? 干表
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE TABLE `aaa` (
??? ->?? `id` int(2) DEFAULT NULL
??? -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;?? 創(chuàng)建和3307上結(jié)構(gòu)一樣的空表
Query OK, 0 rows affected (0.00 sec)
在操作系統(tǒng)層面看下數(shù)據(jù)文件
[root@canal3 leochentest]# ll
total 112
-rw-rw---- 1 mysql mysql? 8556 Feb 23 11:50 aaa.frm
-rw-rw---- 1 mysql mysql 98304 Feb 23 11:50 aaa.ibd
-rw-rw---- 1 mysql mysql??? 61 Feb? 8 14:17 db.opt
mysql> alter table aaa discard tablespace;???? 干掉ibd數(shù)據(jù)文件
Query OK, 0 rows affected (0.00 sec)
[root@canal3 leochentest]# ll
total 16
-rw-rw---- 1 mysql mysql 8556 Feb 23 11:50 aaa.frm
-rw-rw---- 1 mysql mysql?? 61 Feb? 8 14:17 db.opt
?
2 在3307上
mysql> use leochentest;
Database changed
mysql>
mysql>
mysql>
mysql> flush tables aaa for export;????? 鎖表,并產(chǎn)生一個tablename.cfg的文件
Query OK, 0 rows affected (0.00 sec)
3. 在3307上將數(shù)據(jù)aaa.cfg和aaa.ibd文件拷貝到3308的對應目錄下
[root@canal3 leochentest]# cp aaa.{cfg,ibd} /data/mysql/3308/data/leochentest
3307上解鎖表
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
?
4.3308上執(zhí)行導入表空間的文件,并打開slave
mysql> Alter table aaa import tablespace;
Query OK, 0 rows affected (0.01 sec)
mysql> select * from aaa;
+------+
| id?? |
+------+
|??? 1 |
+------+
1 row in set (0.00 sec)
mysql> start slave ;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
?????????????? Slave_IO_State: Waiting for master to send event
????????????????? Master_Host: 10.40.20.44
????????????????? Master_User: repl
????????????????? Master_Port: 3307
??????????????? Connect_Retry: 60
????????????? Master_Log_File: canal3-bin.000002
????????? Read_Master_Log_Pos: 19705
?????????????? Relay_Log_File: canal3-relay-bin.000010
??????????????? Relay_Log_Pos: 284
??????? Relay_Master_Log_File: canal3-bin.000002
???????????? Slave_IO_Running: Yes
??????????? Slave_SQL_Running: Yes
????????????? Replicate_Do_DB:
????????? Replicate_Ignore_DB:
?????????? Replicate_Do_Table:
?????? Replicate_Ignore_Table:
????? Replicate_Wild_Do_Table:
? Replicate_Wild_Ignore_Table:
?????????????????? Last_Errno: 0
?????????????????? Last_Error:
???????????????? Skip_Counter: 0
????????? Exec_Master_Log_Pos: 19705
????????????? Relay_Log_Space: 622
????????????? Until_Condition: None
?????????????? Until_Log_File:
??????????????? Until_Log_Pos: 0
?????????? Master_SSL_Allowed: No
?????????? Master_SSL_CA_File:
?????????? Master_SSL_CA_Path:
????????????? Master_SSL_Cert:
??????????? Master_SSL_Cipher:
?????????????? Master_SSL_Key:
??????? Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
??????????????? Last_IO_Errno: 0
??????????????? Last_IO_Error:
?????????????? Last_SQL_Errno: 0
?????????????? Last_SQL_Error:
? Replicate_Ignore_Server_Ids:
???????????? Master_Server_Id: 3307
????????????????? Master_UUID: bbbe1742-0a4b-11e8-b0c0-00000a28142c
???????????? Master_Info_File: /data/mysql/3308/data/master.info
??????????????????? SQL_Delay: 0
????????? SQL_Remaining_Delay: NULL
????? Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
?????????? Master_Retry_Count: 86400
????????????????? Master_Bind:
????? Last_IO_Error_Timestamp:
???? Last_SQL_Error_Timestamp:
?????????????? Master_SSL_Crl:
?????????? Master_SSL_Crlpath:
?????????? Retrieved_Gtid_Set:
??????????? Executed_Gtid_Set:
??????????????? Auto_Position: 0
1 row in set (0.00 sec)
ERROR:
No query specified
轉(zhuǎn)載于:https://www.cnblogs.com/leochenliang/p/8461844.html
總結(jié)
以上是生活随笔為你收集整理的INNODB表快速迁移的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Notes of fwt
- 下一篇: 转:数据库收缩