詳解介紹mydumper原理

怪我咯
發布: 2017-06-23 13:20:58
原創
2348 人瀏覽過
 mydumper的安裝:#http://www.cnblogs.com/lizhi221/p/7010174.html
# # 
mydumper介紹
MySQL本身的mysqldump工具支援單執行緒工作,依序一個個導出多個表,沒有一個並行的機,這就使得它無法迅速的備份資料。
 
mydumper作為一個實用工具,能夠很好地支援多執行緒工作,可以並行的多執行緒的從表中讀入資料並同時寫到不同的文件裡,這使得它在處理速度方面快於傳統的mysqldump。其特徵之一是在處理過程中需要對清單加以鎖定,因此如果我們需要在工作時段執行備份工作,那麼會造成DML阻塞。但一般現在的MySQL都有主從,備份也大部分都在從上進行,所以鎖的問題可以不用考慮。這樣,mydumper能更好的完成備份任務。
 
mydumper特性
 
①多執行緒備份
②因為是多執行緒邏輯備份,備份後會產生多個備份檔
##③備份時對MyISAM表施加FTWRL( FLUSH TABLES WITH READ LOCK),會阻塞DML語句
#④保證備份資料的一致性
⑤支援檔案壓縮
⑥支援匯出binlog
⑦支援多執行緒復原
⑧支援以守護程式模式工作,定時快照和連續二進位日誌
⑨支援將備份檔案切塊
 
##mydumper參數詳解
 
$ mydumper --helpUsage:
  mydumper [OPTION...] multi-threaded MySQL dumping

Help Options:  -?, --help                  Show help optionsApplication 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主要流程概括
######### #########1、主執行緒FLUSH TABLES WITH READ LOCK, 施加全域唯讀鎖,以阻止DML語句寫入,保證數據的一致性############2、讀取目前時間點的二進位日誌檔案名稱和日誌寫入的位置並記錄在metadata檔案中,以便即使點恢復使用##### #######3、N個(線程數可以指定,預設是4)dump線程START TRANSACTION WITH CONSISTENT SNAPSHOT; 開啟讀取一致的事務############4、dump non -InnoDB tables, 首先匯出非交易引擎的表格############5、主執行緒UNLOCK TABLES 非交易引擎備份完後,釋放全域唯讀鎖定########## ###6、dump InnoDB tables, 基於交易導出InnoDB表格#############7、交易結束######### ##########  mydumper的less locking模式:######### #########     mydumper使用--less-locking可以減少鎖定等待時間,此時mydumper的執行機制大致為####### ## #########     1、主執行緒FLUSH TABLES WITH READ LOCK (全域鎖定)############     2、Dump線程########     3、LL Dump執行緒LOCK TABLES non-InnoDB(執行緒內部鎖定)############     4、主執行緒UNLOCK TABLES######     4、主執行緒UNLOCK TABLES######     4、主執行緒UNLOCK TABLES#######
     5、LL Dump執行緒dump non-InnoDB tables
     6、LL DUmp執行緒UNLOCK non-InnoDB
##o# 、Dump執行緒dump InnoDB tables
 
 
mydumper備份流程圖
 


##

以上是詳解介紹mydumper原理的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!