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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

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`参数强制在创建完备的
子线程后就释放锁,减小备份对业务造成的写堵塞



 本文转自 angry_frog 51CTO博客,原文链接:http://blog.51cto.com/l0vesql/2057223
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
关系型数据库 MySQL Linux
Linux下安装MySQL
Linux下安装MySQL
4 0
|
1天前
|
SQL 分布式计算 关系型数据库
Ubuntu上安装MySQL以及hive
Ubuntu上安装MySQL以及hive
10 1
|
3天前
|
关系型数据库 MySQL Linux
服务器Linux系统配置mysql数据库主从自动备份
这是一个基本的配置主从复制和设置自动备份的指南。具体的配置细节和命令可能因您的环境和需求而有所不同,因此建议在操作前详细阅读MySQL文档和相关资源,并谨慎操作以避免数据丢失或不一致。
12 3
|
3天前
|
关系型数据库 MySQL 数据库
mysqlTools 一分钟部署安装本mysql多个版本,解锁繁琐部署过程
mysqlTools 一分钟部署安装本mysql多个版本,解锁繁琐部署过程
63 2
|
4天前
|
关系型数据库 MySQL 数据库连接
用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections
用Navicat备份Mysql演示系统数据库的时候出:Too Many Connections
18 0
|
4天前
|
关系型数据库 MySQL Linux
本地虚拟机centos7通过docker安装主从mysql5.7.21
本地虚拟机centos7通过docker安装主从mysql5.7.21
14 0
|
6天前
|
关系型数据库 MySQL 数据库
龙蜥操作系统上安装MySQL:步骤详解与常见问题解决
龙蜥操作系统上安装MySQL:步骤详解与常见问题解决
|
6天前
|
关系型数据库 MySQL Linux
在Centos7中:通过Docker安装MySQL5.7(保姆级)
在Centos7中:通过Docker安装MySQL5.7(保姆级)
|
6天前
|
编解码 安全 关系型数据库
祝福CSDN的小伙伴2024年快乐!Windows7安装MySQL
祝福CSDN的小伙伴2024年快乐!Windows7安装MySQL
|
8天前
|
关系型数据库 MySQL 数据管理
MySQL通过 bin-log 恢复从备份点到灾难点之间数据
MySQL通过 bin-log 恢复从备份点到灾难点之间数据