【MySQL】【备份】mydumper安装与使用细节
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,mydumper简介:由percona公司的Max Bubenick与facebook公司的Domas Mituzas共同维护开发,也是个10年历史的工具了,与同为逻辑备份的mysqldump工具而言
千家信息网最后更新 2026年11月02日【MySQL】【备份】mydumper安装与使用细节
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 --helpUsage: mydumper [OPTION...] multi-threaded MySQL dumpingHelp Options: -?, --help Show help optionsApplication 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`参数强制在创建完备的子线程后就释放锁,减小备份对业务造成的写堵塞
备份
事务
线程
一致
编译
一致性
方式
位置
实例
系统
业务
工具
快照
版本
特性
过程
问题
存储
个子
事件
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技园
深圳市人人互联网科技有限公司
北京互联网科技有限公司
互联网科技英文
世界互联网领先科技成果
浩特互联网科技
宜安科技 互联网金融
睿民互联网科技
成都狮子座互联网科技
互联网科技公司的市场部门
深圳前海聚择互联网科技有限公司
消费医药和互联网科技
迪庆互联网科技招生
华夏恒生互联网科技013171
广州燕处互联网科技有限公司
互联网硬科技公司
唐山双旺合互联网科技产业园
10位科技互联网大佬
互联网高科技绘画
互联网 科技节活动 微视频大赛
互联网与科技
西安纸贵互联网科技有限公司
嘟嘟瓜互联网科技
世界互联网领先科技成果
壹账通互联网科技
互联网方面的科技前沿
小米互联网科技园入驻
银川新华互联网科技学校招聘
前海云享互联网科技
武汉亿视互联网科技有限公司