mydumper原理介紹

 
 
mydumper介紹
 
MySQL自身的mysqldump工具支持單線程工做,依次一個個導出多個表,沒有一個並行的機,這就使得它沒法迅速的備份數據。
 
mydumper做爲一個實用工具,可以良好支持多線程工做,能夠並行的多線程的從表中讀入數據並同時寫到不一樣的文件裏,這使得它在處理速度方面快於傳統的mysqldump。其特徵之一是在處理過程當中須要對列表加以鎖定,所以若是咱們須要在工做時段執行備份工做,那麼會引發DML阻塞。但通常如今的MySQL都有主從,備份也大部分在從上進行,因此鎖的問題能夠不用考慮。這樣,mydumper能更好的完成備份任務。
 
mydumper特性
 
①多線程備份
②由於是多線程邏輯備份,備份後會生成多個備份文件
③備份時對MyISAM表施加FTWRL(FLUSH TABLES WITH READ LOCK),會阻塞DML語句
④保證備份數據的一致性
⑤支持文件壓縮
⑥支持導出binlog
⑦支持多線程恢復
⑧支持以守護進程模式工做,定時快照和連續二進制日誌
⑨支持將備份文件切塊
 
mydumper參數詳解
 
$ mydumper --help
Usage:
  mydumper [OPTION...] multi-threaded MySQL dumping

Help Options:
  -?, --help                  Show help options

Application Options:
  -B, --database              要備份的數據庫,不指定則備份全部庫
  -T, --tables-list           須要備份的表,名字用逗號隔開
  -o, --outputdir             備份文件輸出的目錄
  -s, --statement-size        生成的insert語句的字節數,默認1000000
  -r, --rows                  Try to split tables into chunks of this many rows. This option turns off --chunk-filesize
  -F, --chunk-filesize        Split tables into chunks of this output file size. This value is in MB
  -c, --compress              Compress output files壓縮輸出文件
  -e, --build-empty-files     若是表數據是空,仍是產生一個空文件(默認無數據則只有表結構文件)
  -x, --regex                 Regular expression for 'db.table' matching 使用正則表達式匹配'db.table'
  -i, --ignore-engines        Comma delimited list of storage engines to ignore忽略的存儲引擎,用逗號分割
  -m, --no-schemas            Do not dump table schemas with the data不備份表結構,只備份數據
  -d, --no-data               Do not dump table data備份表結構,不備份數據
  -G, --triggers              Dump triggers備份觸發器
  -E, --events                Dump events
  -R, --routines              Dump stored procedures and functions備份存儲過程和函數
  -k, --no-locks              不使用臨時共享只讀鎖,使用這個選項會形成數據不一致
  --less-locking              Minimize locking time on InnoDB tables.減小對InnoDB表的鎖施加時間
  -l, --long-query-guard      設定阻塞備份的長查詢超時時間,單位是秒,默認是60秒(超時後默認mydumper將會退出)
  -K, --kill-long-queries     Kill long running queries (instead of aborting)殺掉長查詢 (不退出)
  -D, --daemon                Enable daemon mode啓用守護進程模式,守護進程模式以某個間隔不間斷對數據庫進行備
  -I, --snapshot-interval     dump快照間隔時間,默認60s,須要在daemon模式下
  -L, --logfile               使用的日誌文件名(mydumper所產生的日誌), 默認使用標準輸出
  --tz-utc                    SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones, defaults to on use --skip-tz-utc to disable.
  --skip-tz-utc               
  --use-savepoints            使用savepoints來減小採集metadata所形成的鎖時間,須要 SUPER 權限
  --success-on-1146           Not increment error count and Warning instead of Critical in case of table doesn't exist
  --lock-all-tables           Use LOCK TABLE for all, instead of FTWRL
  -U, --updated-since         Use Update_time to dump only tables updated in the last U days
  --trx-consistency-only      Transactional consistency only
  -h, --host                  鏈接的主機名
  -u, --user                  用來備份的用戶名
  -p, --password              用戶密碼
  -P, --port                  鏈接端口
  -S, --socket                使用socket通訊時的socket文件
  -t, --threads               開啓的備份線程數,默認是4
  -C, --compress-protocol     壓縮與mysql通訊的數據
  -V, --version               顯示版本號
  -v, --verbose               輸出信息模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默認爲2
 
mydumper主要流程歸納
 
一、主線程 FLUSH TABLES WITH READ LOCK, 施加全局只讀鎖,以阻止DML語句寫入,保證數據的一致性
二、讀取當前時間點的二進制日誌文件名和日誌寫入的位置並記錄在metadata文件中,以供即便點恢復使用
三、N個(線程數能夠指定,默認是4)dump線程 START TRANSACTION WITH CONSISTENT SNAPSHOT; 開啓讀一致的事務
四、dump non-InnoDB tables, 首先導出非事務引擎的表
五、主線程 UNLOCK TABLES 非 事務引擎備份完後,釋放全局只讀鎖
六、dump InnoDB tables, 基於 事務導出InnoDB表
七、事務結束
 
  mydumper的less locking模式:
 
     mydumper使用--less-locking能夠減小鎖等待時間,此時mydumper的執行機制大體爲
 
     一、主線程 FLUSH TABLES WITH READ LOCK (全局鎖)
     二、Dump線程 START TRANSACTION WITH CONSISTENT SNAPSHOT;
     三、LL Dump線程 LOCK TABLES non-InnoDB (線程內部鎖)
     四、主線程UNLOCK TABLES
     五、LL Dump線程 dump non-InnoDB tables
     六、LL DUmp線程 UNLOCK non-InnoDB
     七、Dump線程 dump InnoDB tables
 
 
mydumper備份流程圖
 
相關文章
相關標籤/搜索