码迷,mamicode.com
首页 > 其他好文 > 详细

mydumper安装笔记

时间:2016-06-30 23:36:09      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:mydumper的使用

参考: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要高很多。

mydumper安装笔记

标签:mydumper的使用

原文地址:http://lee90.blog.51cto.com/10414478/1794708

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!