广告
返回顶部
首页 > 资讯 > 数据库 >【MySQL】【备份】mydumper安装与使用细节
  • 429
分享到

【MySQL】【备份】mydumper安装与使用细节

2024-04-02 19:04:59 429人浏览 泡泡鱼
摘要

mydumper 简介: 由percona公司的Max Bubenick与facebook公司的Domas Mituzas共同维护开发,也是个10年历史的工具了, 与同为逻辑备份的Mysqldump

mydumper

简介:

由percona公司的Max Bubenick与facebook公司的Domas Mituzas共同维护开发,也是个10年历史的工具了,
与同为逻辑备份的Mysqldump工具而言,其特性在于多线程并行备份,与官方同类型的mysqlpump相比,其优点
在于一张表可以分到好几个线程上进行备份。

安装:

很多博客都推荐使用编译的方式进行安装 ,在这里点一下坑,由于mydumper依赖了 glib2-devel 
mysql-devel zlib-devel pcre-devel openssl-devel等第三方库,而这些库之前并没有按系统默认方式安装
到各个默认位置,那么将会产生编译安装的连指定编译位置的问题。我在Cent7系统上安装时,就遇到
很多编译不通过或者编译后使用报错的问题,检查环境后发现系统运维的同事使用编译安装的方式安装了
MySQL 5.6与pcre库。后面我尝试使用yum安装库后,还是无法排除问题。

 在这里我推荐使用开发者编译好的rpm包进行安装,配合yum可以自动补齐依赖,避免很多坑。

 地址:https://GitHub.com/maxbube/mydumper/releases,请根据自己的系统类型选择下载版本。

`yum -y install Https://github.com/maxbube/mydumper/releases/download/v0.9.3/mydumper-0.9.3-41.el7.x86_64.rpm`

使用:

$mydumper --help
Usage:
  mydumper [OPTioN...] multi-threaded MySQL dumping

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

Application Options:
  -B, --database              Database to dump
  -T, --tables-list           Comma delimited table list to dump (does not exclude regex option)
  -o, --outputdir             Directory to output files to
  -s, --statement-size        Attempted size of INSERT statement in bytes, default 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     Build dump files even if no data available from table
  -x, --regex                 Regular expression for 'db.table' matching
  -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
  -W, --no-views              Do not dump VIEWs
  -k, --no-locks              Do not execute the temporary shared read lock.  WARNING: This will cause inconsistent backups
  --no-backup-locks           Do not use Percona backup locks
  --less-locking              Minimize locking time on InnoDB tables.
  -l, --long-query-guard      Set long query timer in seconds, default 60
  -K, --kill-long-queries     Kill long running queries (instead of aborting)
  -D, --daemon                Enable daemon mode
  -I, --snapshot-interval     Interval between each dump snapshot (in minutes), requires --daemon, default 60
  -L, --logfile               Log file name to use, by default stdout is used
  --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            Use savepoints to reduce metadata locking issues, needs SUPER privilege
  --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
  --complete-insert           Use complete INSERT statements that include column names
  -h, --host                  The host to connect to
  -u, --user                  Username with the necessary privileges
  -p, --passWord              User password
  -P, --port                  tcp/IP port to connect to
  -S, --Socket                UNIX domain socket file to use for connection
  -t, --threads               Number of threads to use, default 4
  -C, --compress-protocol     Use compression on the MySQL connection
  -V, --version               Show the program version and exit
  -v, --verbose               Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
  --defaults-file             Use a specific defaults file

这里给出我最常用的备份方式:

mydumper -h 192.168.1.109 -P 3109 -u root -p 123456 -G -E -R -t 4 -c -o /data/bak/mysql/3109

说明:-h 指定地址

   -P 指定备份端口

   -u 指定备份用户

   -p 密码

   -G 备份触发器

   -E  备份定时事件

   -R  备份存储过程和函数

   -t  备份时并发的线程数(不包含备份主线程)

       -c  对备份文件进行压缩(gz方式)

   -o  指定备份存储位置

原理与过程:

与mysqldump工具类似,先FTWRL(flush table with read lock),查询自己本身的事务执行位置(show 
master status),然后开启一个一致性快照事务,再启动若干个子线程分别开启一致性可重复读快照事务,
使用子线程开启事务并读取数据和视图,函数,存储过程,定时事件等。由于实例中可能有非事务型表的
存在,为保持一致性,待各个子线程全部备份完非事务型的表后才会释放FTWRL。

这里重点说明下`--trx-consistency-only`参数,很多博客都是粗粗点过甚至不翻译。上一步中我们说到
mydumper为了获取整个实例级别的一致性备份,会在开始备份时加上FTWRL,待各个线程都备份完非事务
表后,才会释放FTWRL。这是考虑到5.7及之前的版本中mysql库的部分表是MyISAM引擎,不具备事务特
性,或者业务上还存在非事务表。但8.0之后的版本中mysql库全部改成了InnoDB引擎,或者用户选择不备
份mysql库,或者实例中一张非事务表都没有,这时mydumper会在创建完所有子线程并分别开启一致性可
重复读快照事务后就释放FTWRL.因为这个时候根据事务特性已经可以保证备份一致了。

若你确定没有备份非事务型表,或者没有备份mysql库,或者实例中非事务表的一致性无关紧要,在你非常
介意备份时加的读锁对业务造成的影响的话,可以考虑加上`--trx-consistency-only`参数强制在创建完备的
子线程后就释放锁,减小备份对业务造成的写堵塞
您可能感兴趣的文档:

--结束END--

本文标题: 【MySQL】【备份】mydumper安装与使用细节

本文链接: https://www.lsjlt.com/news/41974.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作