久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

mysql表空間傳輸過程

161次閱讀
沒有評論

共計 3730 個字符,預計需要花費 10 分鐘才能閱讀完成。

本篇內容介紹了“mysql 表空間傳輸過程”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓丸趣 TV 小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

在 MySQL 5.6 版本中引入了一個可移動表空間的新特性(復制的表空間到另一個服務器),即 mysql 表空間傳輸。這使得我們傳輸表或者單個庫的數(shù)據(jù)變得十分方便。

    但是,傳輸表空間必須滿足以下的條件

1. 必須使用獨立表空間

2. 兩個 mysql 數(shù)據(jù)庫的 page 大小必須一樣

3. 兩個表的表結構必須一樣

下面我們對 lala 庫下面的 score 表進行傳輸

首先,先從主庫導出 score

我們可以在導出之前對錯誤日志 - f 命令進行輸出,跟蹤它做了什么

[root@potato data]# tail -f error.log

root@localhost:mysql.sock  01:31:46 [lala] flush tables score for export;

root@localhost:mysql.sock  02:08:21 [lala] select * from score;                 +——+———-+——-+

| id   | name     | score |

+——+———-+——-+

|    3 | xiaohong |    99 |

|    2 | xiaoming |    65 |

|    1 | xiaojun  |    55 |

+——+———-+——-+

3 rows in set (0.00 sec)

以下是錯誤日志的輸出

2016-12-19 01:32:44 25547 [Note] InnoDB: Sync to disk of lala . score started.

2016-12-19 01:32:44 25547 [Note] InnoDB: Stopping purge

2016-12-19 01:32:44 25547 [Note] InnoDB: Writing table metadata to ./lala/score.cfg

2016-12-19 01:32:44 25547 [Note] InnoDB: Table lala . score flushed to disk

可見,它首先對表停止操作,再把 score 的數(shù)據(jù)和元數(shù)據(jù)寫到磁盤。

此時可以訪問這張表,但是不能對數(shù)據(jù)進行 DML 操作,如

發(fā)起查詢語句,成功

root@localhost:mysql.sock  01:33:11 [(none)] select * from lala.score;          +——+———-+——-+

| id   | name     | score |

+——+———-+——-+

|    3 | xiaohong |    99 |

|    2 | xiaoming |    65 |

|    1 | xiaojun  |    55 |

+——+———-+——-+

3 rows in set (0.00 sec)

發(fā)起插入語句,一直在等待

root@localhost:mysql.sock  01:31:23 [(none)] insert into lala.score values(4, xiaolin ,74);

在庫文件夾下面多了 cfg 文件

[root@potato lala]# ls -l score*

-rw-r—–. 1 mysql mysql   470 Dec 19 02:07 score.cfg

-rw-rw—-. 1 mysql mysql  8618 Dec 19 02:03 score.frm

-rw-r—–. 1 mysql mysql 98304 Dec 19 02:07 score.ibd

我們把 cfg 和 ibd 文件先復制到 /tmp 目錄下

[root@potato lala]#cp score.cfg /tmp

[root@potato lala]#cp score.ibd /tmp

然后解鎖表,讓外部可以盡快訪問表

root@localhost:mysql.sock  01:35:02 [lala] unlock tables;

Query OK, 0 rows affected (0.00 sec)

備庫此時沒有該表

root@localhost:mysql.sock  01:35:28 [lala] show tables;

+—————-+

| Tables_in_lala |

+—————-+

| haha           |

| test           |

| test1          |

+—————-+

3 rows in set (0.00 sec)

查看主庫的 score 建表語句

root@localhost:mysql.sock  01:37:19 [lala] show create table score\G

*************************** 1. row ***************************

Table: score

Create Table: CREATE TABLE `score` (

`id` int(11) DEFAULT NULL,

`name` varchar(15) DEFAULT NULL,

`score` int(11) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8

1 row in set (0.00 sec)

在從庫上執(zhí)行

root@localhost:mysql.sock  02:03:44 [lala] CREATE TABLE `score` (

–    `id` int(11) DEFAULT NULL,

–    `name` varchar(15) DEFAULT NULL,

–    `score` int(11) DEFAULT NULL

– ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Query OK, 0 rows affected (0.02 sec)

現(xiàn)在 score 表是沒有數(shù)據(jù)的

root@localhost:mysql.sock  02:04:11 [lala] select * from score;

Empty set (0.00 sec)

卸載 score 表空間

root@localhost:mysql.sock  02:05:12 [lala] alter table score discard tablespace;

Query OK, 0 rows affected (0.02 sec)

[root@potato lala]# ls -l score*

-rw-rw—-. 1 mysql mysql 8618 Dec 19 02:03 score.frm

在主庫上把兩個文件傳到備庫上

[root@potato lala]# scp /tmp/score* 192.168.161.55:/data/mysql/mytest_3306/data/lala

root@192.168.161.55 s password:

score.cfg                                     100%  470     0.5KB/s   00:00   

score.ibd                                     100%   96KB  96.0KB/s   00:00

修改傳輸過去的文件屬主

[root@potato lala]# ls -l score*

-rw-r—–. 1 root root  8618 Dec 19 01:37 score.cfg

-rw-rw—-. 1 mysql mysql  8618 Dec 19 02:03 score.frm

-rw-r—–. 1 root root 98304 Dec 19 01:37 score.ibd

[root@potato lala]# chown mysql:mysql score*

[root@potato lala]# ls -l score*

-rw-r—–. 1 mysql mysql   470 Dec 19 02:07 score.cfg

-rw-rw—-. 1 mysql mysql  8618 Dec 19 02:03 score.frm

-rw-r—–. 1 mysql mysql 98304 Dec 19 02:07 score.ibd

導入 score 表空間

root@localhost:mysql.sock  02:05:29 [lala] alter table score import tablespace; Query OK, 0 rows affected (0.36 sec)

root@localhost:mysql.sock  02:08:21 [lala] select * from score;                 +——+———-+——-+

| id   | name     | score |

+——+———-+——-+

|    3 | xiaohong |    99 |

|    2 | xiaoming |    65 |

|    1 | xiaojun  |    55 |

+——+———-+——-+

3 rows in set (0.00 sec)
      至此,表空間傳輸成功

“mysql 表空間傳輸過程”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注丸趣 TV 網(wǎng)站,丸趣 TV 小編將為大家輸出更多高質量的實用文章!

正文完
 
丸趣
版權聲明:本站原創(chuàng)文章,由 丸趣 2023-07-28發(fā)表,共計3730字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網(wǎng)絡搜集發(fā)布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 五家渠市| 云浮市| 漯河市| 鄂托克旗| 乾安县| 北宁市| 蚌埠市| 湘阴县| 新密市| 新乡县| 赤峰市| 正阳县| 寻乌县| 武鸣县| 永仁县| 汽车| 高陵县| 丘北县| 恭城| 阿拉善左旗| 蕲春县| 东宁县| 永平县| 广灵县| 常宁市| 庄浪县| 永新县| 合肥市| 宁化县| 浏阳市| 金秀| 台北市| 澄江县| 新丰县| 东丰县| 弥勒县| 托克托县| 雷波县| 云阳县| 石阡县| 蒙自县|