MySQL 表空間傳送

1、源庫查詢表結構

mysql> show create table s_show\G
*************************** 1. row ***************************
       Table: study_show
Create Table: CREATE TABLE `study_show` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) DEFAULT '0' ,
  `course_id` int(11) DEFAULT '0'  ,
  `ishow` tinyint(1) DEFAULT '0' ,
  `album_id` int(10) DEFAULT '0' ,
  `group_id` int(11) DEFAULT '0' ,
  `task_id` int(11) DEFAULT '0' ,
  `video` varchar(40) DEFAULT '' ,
  `show_pic` int(11) DEFAULT '0' ,
  `create_time` int(11) DEFAULT '0' ,
  PRIMARY KEY (`id`),
  KEY `uid` (`uid`) USING BTREE,
  KEY `course_id` (`course_id`) USING BTREE,
  KEY `create_time` (`create_time`)
) ENGINE=InnoDB AUTO_INCREMENT=35230183 DEFAULT CHARSET=utf8 
1 row in set (0.00 sec)


2、目標庫創建表

mysql> CREATE TABLE `s_show` (
    ->   `id` int(11) unsigned NOT NULL AUTO_INCREMENT ,
    ->   `uid` int(11) DEFAULT '0' ,
    ->   `course_id` int(11) DEFAULT '0' ,
    ->   `ishow` tinyint(1) DEFAULT '0' ,
    ->   `album_id` int(10) DEFAULT '0' ,
    ->   `group_id` int(11) DEFAULT '0' ,
    ->   `task_id` int(11) DEFAULT '0' ,
    ->   `video` varchar(40) DEFAULT '' ,
    ->   `show_pic` int(11) DEFAULT '0' ,
    ->   `create_time` int(11) DEFAULT '0' ,
    ->   PRIMARY KEY (`id`),
    ->   KEY `uid` (`uid`) USING BTREE,
    ->   KEY `course_id` (`course_id`) USING BTREE,
    ->   KEY `create_time` (`create_time`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
Query OK, 0 rows affected (0.32 sec)


mysql> desc s_show;
+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| id          | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| uid         | int(11)          | YES  | MUL | 0       |                |
| course_id   | int(11)          | YES  | MUL | 0       |                |
| ishow       | tinyint(1)       | YES  |     | 0       |                |
| album_id    | int(10)          | YES  |     | 0       |                |
| group_id    | int(11)          | YES  |     | 0       |                |
| task_id     | int(11)          | YES  |     | 0       |                |
| video       | varchar(40)      | YES  |     |         |                |
| show_pic    | int(11)          | YES  |     | 0       |                |
| create_time | int(11)          | YES  | MUL | 0       |                |
+-------------+------------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)

mysql> select * from s_show;
Empty set (0.00 sec)



3、目標庫禁用表空間

mysql> alter table s_show discard tablespace;
Query OK, 0 rows affected (0.05 sec)


4、源庫鎖定表

mysql> flush table s_show for export;
Query OK, 0 rows affected (0.05 sec)


5、複製文件到目標庫

[root@node01 mydb_1]# ls -alh|grep "s_show\."
-rw-r-----  1 mysql mysql 1.2K Aug 10 11:52 s_show.cfg
-rw-r-----  1 mysql mysql 8.9K Aug  9 14:02 s_show.frm
-rw-r-----  1 mysql mysql 5.0G Aug  9 14:46 s_show.ibd


[root@node01 mydb_1]# scp s_show.{cfg,ibd} [email protected]:/u01/mydata/mydb_1/
[email protected]'s password: 
s_show.cfg                                                                                                100% 1152     1.1KB/s   00:00    
s_show.ibd                                                                                                100% 5024MB  19.9MB/s   04:13


6、目標庫導入表空間

修改文件權限
[root@node02 mydb_1]# chown -R mysql:mysql /u01/mydata/mydb_1/s_show.{cfg,ibd}
導入表空間(如果表很大會有很高的IO)
mysql> alter table s_show import tablespace;
Query OK, 0 rows affected (6 min 32.76 sec)


7、源庫解除鎖表

mysql> UNLOCK TABLES;
Query OK, 0 rows affected (0.05 sec)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章