mydumper myloader使用介紹

2021-08-25 11:02:25 字數 4133 閱讀 9357

更快的,mysql資料庫多執行緒匯入匯出工具。

ubuntu or debian: apt-get install libglib2.0-dev libmysqlclient15-dev zlib1g-dev libpcre3-dev libssl-dev

fedora, redhat and centos: yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel

opensuse: zypper install glib2-devel libmysqlclient-devel pcre-devel zlib-devel

macosx: port install glib2 mysql5 pcre pkgconfig cmake

[root@10-127-33-80 data]# tar -zxvf mydumper-0.9.1.tar.gz

[root@10-127-33-80 data]#cd mydumper-0.9.1

[root@10-127-33-80 mydumper-0.9.1]# cmake .

[root@10-127-33-80 mydumper-0.9.1]# make && make install

mydumper -u root -p redhat -s /tmp/mysql_13308.sock -t 16 -b test -o /data/test

匯出檔案示例:

[root@10-127-33-80 test]# ll -h

total 61g

-rw-r–r– 1 root root 532 jul 19 17:47 metadata

-rw-r–r– 1 root root 382 jul 19 17:46 test.sbtest10-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest10.sql

-rw-r–r– 1 root root 382 jul 19 17:46 test.sbtest11-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest11.sql

-rw-r–r– 1 root root 382 jul 19 17:46 test.sbtest12-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest12.sql

-rw-r–r– 1 root root 382 jul 19 17:46 test.sbtest13-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest13.sql

-rw-r–r– 1 root root 382 jul 19 17:46 test.sbtest14-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest14.sql

-rw-r–r– 1 root root 382 jul 19 17:46 test.sbtest15-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest15.sql

-rw-r–r– 1 root root 382 jul 19 17:46 test.sbtest16-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest16.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest1-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest1.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest2-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest2.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest3-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest3.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest4-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest4.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest5-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest5.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest6-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest6.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest7-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest7.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest8-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:46 test.sbtest8.sql

-rw-r–r– 1 root root 380 jul 19 17:46 test.sbtest9-schema.sql

-rw-r–r– 1 root root 3.8g jul 19 17:47 test.sbtest9.sql

-rw-r–r– 1 root root 63 jul 19 17:46 test-schema-create.sql

61g sql檔案匯出時間大概為:

[root@10-127-33-80 data]# time sh mydumper.sh

real 0m29.172s

user 4m56.947s

sys 1m49.880s

匯出多個庫用法

mydumper -u root -p root123 -s /tmp/mysql3308.sock -t 16 –regex 『a|b』 -o /data/test //使用regex正則匹配

也可以使用–regex 『^(?!(mysql|test))』 這種方式去反向過濾。

myloader -u root -p redhat -s /tmp/mysql_13308.sock -t 16 -b test -d /data/test/

real 19m50.933s

user 1m18.263s

sys 0m48.272s

注意事項

1,多執行緒匯出會耗盡磁碟io,爭奪innodb記憶體池,擠掉熱資料。應該在系統訪問量最低時進行,避免影響線上業務

2,匯出匯入不支援管道

3,不支援隱式密碼輸入,安全起見,放在shell指令碼中執行。

0,撈取所有待匯入的表結構,以及對於的innodb行數級別,根據表寬度和行數級別,制定併發執行計畫

1,執行flush tables with read lock,禁止資料寫入

2,show master status;獲取gtid

3,開啟多執行緒, set session transaction isolation level repeatable read;start transaction with consistent snapshot;

4,unlock tables;釋放全域性讀鎖

5,各執行緒資料匯出,獲取表結構資訊,備份過程結束,斷開執行緒。

1,目前只能匯出到檔案,再匯入資料庫,如果支援直接匯出匯入,可以節約更多的時間

2,匯出表順序問題,如果考慮到資料量大小,也可以節省很多時間。

iOS description方法的使用介紹

在輸出字串 一些基本資料型別以及 oc 物件,我們都可以使用 nslog 函式進行輸出。本次主要談談使用nslog輸出 oc 物件的應用。一般情況下,我們在使用nslog 和 輸出某個物件時,就會呼叫這個物件的 description 方法,它的返回值就是 nsstring 字串型別,所以 desc...

HiveSQL中row number使用介紹

方式一 select t2.user log acct t2.item sku id t2.time from select from distribute by item sku id sort by user log acct,item sku id,time desc t2 where row...

Mysql點滴 DATE FORMAT使用介紹

基本上每個專案的資料庫的表都要涉及到時間方面,在進行資料統計的時候,會發現很多需要對資料進行統計,當然啦,肯定是基於時間來進行的 這個時候,可以使用mysql 內建的date format函式來進行 mysql點滴 date format date format date,format 根據form...