mydumper安裝筆記
- 2019 年 10 月 4 日
- 筆記
參考:http://www.tuicool.com/articles/2eAVVvN
mydumper備份的速度、myloader的恢復速度,比mysql自己的工具執行速度快很多,大大減少業務的處理時間。
# yum install glib2-develmysql-devel zlib-devel pcre-devel -y # wget https://launchpadlibrarian.net/225370879/mydumper-0.9.1.tar.gz # cmake ./ #make && make install
mydumper參數介紹:
-B, --database Database to dump -T,--tables-list Comma delimitedtable list to dump (does not exclude regex option) -o, --outputdir Directory to output files to -s,--statement-size Attempted size ofINSERT statement in bytes, default 1000000 -r,--rows Try to splittables into chunks of this many rows. This option turns off --chunk-filesize -F,--chunk-filesize Split tables intochunks of this output file size. This value is in MB -c,--compress Compress outputfiles -e,--build-empty-files Build dump fileseven if no data available from table -x,--regex Regularexpression for 'db.table' matching -i,--ignore-engines Comma delimitedlist of storage engines to ignore -m, --no-schemas Do notdump table schemas with the data -d, --no-data Do notdump table data -G,--triggers Dump triggers -E,--events Dump events -R,--routines Dump storedprocedures and functions -k,--no-locks Do not executethe temporary shared read lock. WARNING:This will cause inconsistent backups --less-locking Minimize locking time on InnoDB tables. -l,--long-query-guard Set long querytimer in seconds, default 60 -K,--kill-long-queries Kill long runningqueries (instead of aborting) -D, --daemon Enabledaemon mode -I, --snapshot-interval Interval between each dump snapshot (in minutes), requires --daemon, default60 -L,--logfile Log file name touse, by default stdout is used --tz-utc SETTIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when aserver has data in different time zones or data is being moved between serverswith different time zones, defaults to on use --skip-tz-utc to disable. --skip-tz-utc --use-savepoints Usesavepoints to reduce metadata locking issues, needs SUPER privilege --success-on-1146 Not increment error count and Warning insteadof Critical in case of table doesn't exist --lock-all-tables UseLOCK TABLE for all, instead of FTWRL -U,--updated-since Use Update_timeto dump only tables updated in the last U days --trx-consistency-only Transactional consistency only -h,--host The host toconnect to -u,--user Username withprivileges to run the dump -p,--password User password -P,--port TCP/IP port toconnect to -S,--socket UNIX domainsocket file to use for connection -t, --threads Numberof threads to use, default 4 -C,--compress-protocol Use compressionon the MySQL connection -V,--version Show the programversion and exit -v,--verbose Verbosity ofoutput, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
myloader參數介紹:
-d,--directory Directoryof the dump to import導入備份目錄 -q,--queries-per-transaction Number ofqueries per transaction, default 1000 -o,--overwrite-tables Drop tablesif they already exist如果表存在刪除表 -B,--database Analternative database to restore into需要還原的庫 -s,--source-db Database torestore -e,--enable-binlog Enablebinary logging of the restore data -h,--host The host toconnect to -u,--user Usernamewith privileges to run the dump -p,--password Userpassword -P,--port TCP/IP portto connect to -S,--socket UNIX domainsocket file to use for connection -t,--threads Number ofthreads to use, default 4使用的執行緒數量,默認4 -C,--compress-protocol Usecompression on the MySQL connection -V,--version Show theprogram version and exit -v,--verbose Verbosityof output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
mydumper輸出文件說明:
metadata:元數據,記錄備份開始和結束時間,以及binlog日誌文件位置。 table data:每個表一個文件 table schemas:表結構文件 daemon mode:在這個模式下,有五個目錄0,1,binlogs,binlog_snapshot,last_dump。 備份目錄是0和1,間隔備份,如果mydumper因某種原因失敗而仍然有一個好的快照, 當快照完成後,last_dump指向該備份。
mydumper用例
備份hellodb資料庫到當前目錄下
# mydumper -uroot -proot -B hellodb -o ./ # ll 是每個表單獨備份的

# cat metadata 可以看到

以守護進程方式每30分鐘備份一次 # mydumper -uroot -proot -B hellodb-o /home/data/bak -D -I 30 資料庫的還原覆蓋操作 # myloader -o -B hellodb -o -d/home/data/bak/last_dump
最後,附上一個mysqldump和mydumper的速度對比圖。
[root@db ~]# time mysqldump -uroot -proot -B Mobile > aa.sql real 0m1.863s user 0m1.571s sys 0m0.164s
[root@db ~]# time mydumper -u root -p root -B Mobile -o /db/backup/mobile/ real 0m0.851s user 0m0.735s sys 0m0.101s
很明顯地可以看出mydumper的效率比mysqldump要高很多。