安装
下载安装包:
wget https://launchpad.net/mydumper/0.9/0.9.1/+download/mydumper-0.9.1.tar.gz

安装依赖包:
yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel cmake

## mydumper是C语句开发,编译依赖gcc和gcc-c++,如果编译出现C语言相关报错可yum install gcc gcc-c++
## mydumper-0.9.1依赖5.7的mysql-devel,所以必须安装5.7的mysql-devel

tar zxvf mydumper-0.9.1.tar.gz
cd mydumper-0.9.1
cmake .
make
make install

安装完成后生成两个二进制文件mydumper和myloader位于/usr/local/bin目录下
查看是否正常:
mydumper --help

流程
mydumper主要流程概括:

1、主线程 FLUSH TABLES WITH READ LOCK, 施加全局只读锁,以阻止DML语句写入,保证数据的一致性
2、读取当前时间点的二进制日志文件名和日志写入的位置并记录在metadata文件中,以供即使点恢复使用
3、N个(线程数可以指定,默认是4)dump线程 START TRANSACTION WITH CONSISTENT SNAPSHOT; 开启读一致的事务
4、dump non-InnoDB tables, 首先导出非事务引擎的表
5、主线程 UNLOCK TABLES 非 事务引擎备份完后,释放全局只读锁
6、dump InnoDB tables, 基于 事务导出InnoDB表
7、事务结束

mydumper使用--less-locking可以减少锁等待时间,此时mydumper的执行机制大致为

1、主线程 FLUSH TABLES WITH READ LOCK (全局锁)
2、Dump线程 START TRANSACTION WITH CONSISTENT SNAPSHOT;
3、LL Dump线程 LOCK TABLES non-InnoDB (线程内部锁)
4、主线程UNLOCK TABLES
5、LL Dump线程 dump non-InnoDB tables
6、LL DUmp线程 UNLOCK non-InnoDB
7、Dump线程 dump InnoDB tables

参数

mydumper参数详解
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 #生成的insert语句的字节数,默认1000000
-r, --rows Try to split tables into chunks of this many rows. This option turns off --chunk-filesize #指定行切割表,使用时关闭--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 #使用正则表达式匹配'db.table'
-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 #备份存储过程和函数
-k, --no-locks Do not execute the temporary shared read lock. WARNING: This will cause inconsistent backups #不使用临时共享只读锁,使用这个选项会造成数据不一致
--less-locking Minimize locking time on InnoDB tables. #减少对InnoDB表的锁施加时间
-l, --long-query-guard Set long query timer in seconds, default 60 #设定阻塞备份的长查询超时时间,单位是秒,默认是60秒(超时后默认mydumper将会退出)
-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 #dump快照间隔时间,默认60s,需要在daemon模式下
-L, --logfile Log file name to use, by default stdout is used #使用的日志文件名(mydumper所产生的日志), 默认使用标准输出
--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 #使用savepoints来减少采集metadata所造成的锁时间,需要 SUPER 权限
--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
-h, --host The host to connect to #主机名
-u, --user Username with privileges to run the dump #用户
-p, --password User password #密码
-P, --port TCP/IP port to connect to #端口
-S, --socket UNIX domain socket file to use for connection #使用socket通信时的socket文件
-t, --threads Number of threads to use, default 4 #开启的备份线程数,默认是4
-C, --compress-protocol Use compression on the MySQL connection #压缩与mysql通信的数据
-V, --version Show the program version and exit #显示版本号
-v, --verbose Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2 #输出信息模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默认为2

PS:mydumper没有—where参数,部分场景不适用

myloader参数详解
Application Options:
-d, --directory Directory of the dump to import #备份文件路径
-q, --queries-per-transaction Number of queries per transaction, default 1000 #每个事务的query数量, 默认1000
-o, --overwrite-tables Drop tables if they already exist #如果表存在则先删除,使用该参数,需要备份时候要备份表结构,不然还原会找不到表
-B, --database An alternative database to restore into #指定需要还原的数据库
-s, --source-db Database to restore #还原的数据库
-e, --enable-binlog Enable binary logging of the restore data #启用二进制日志恢复数据
-h, --host The host to connect to #主机名
-u, --user Username with privileges to run the dump #账号
-p, --password User password #密码
-P, --port TCP/IP port to connect to #端口
-S, --socket UNIX domain socket file to use for connection #使用socket通信时的socket文件
-t, --threads Number of threads to use, default 4 #开启的恢复线程数,默认是4
-C, --compress-protocol Use compression on the MySQL connection #压缩与mysql通信的数据
-V, --version Show the program version and exit#显示版本号
-v, --verbose Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2 #输出信息模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默认为2

样例

备份多线程单表,必须启用-r指定行数拆分单表为多个文件,会生成多个文件

mydumper -u xxx -p xxx -h xxx -P 3307 -B lgjdb -T yyd_users,liangtab -t 4 -r 3000000 -o /root/lgj -c -C -l 200 &

过滤特定库,如本来不备份mysql及test库
# mydumper -u 用户名 -p 密码  --regex '^(?!(mysql|test))' -o /tmp/bak

还原数据
myloader -u xxx -p xxx -h xxx -P 3307 -B lgjdb -d /root/lgj

mydumper安装和使用的更多相关文章

  1. MySQL 之mydumper安装详解

    方法一: 安装依赖包: 1 yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel cmake make 下载二 ...

  2. mydumper安装及使用

    mydumper 官网:https://launchpad.net/mydumper 安装方式: 1.yum install glib2-devel mysql-devel zlib-devel pc ...

  3. mydumper 安装报错处理

    mydumper 官网:https://launchpad.net/mydumper 下载之后,安装报错: [root@localhost local]# cd mydumper-0.6.2 [roo ...

  4. mydumper安装、原理介绍

    一.安装   安装依赖包: yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel cmake 下载二进制包: ...

  5. mydumper安装

    安装依赖包: yum install glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel cmake 下载二进制包: wget ht ...

  6. mydumper安装及安装故障汇总

     mydumper是针对mysql数据库备份的一个轻量级第三方的开源工具,备份方式术语逻辑备份.它支持多线程.备份速度远高于原生态的mysqldump以及众多优异特性. 因此该工具是DBA们的不二选 ...

  7. mydumper原理4

    Mydumper是一个针对mysql和Drizzle的高性能多线程备份和恢复工具.开发人员分别来自MySQL,Facebook,SkySQL公司.目前已经在有一些大型产品业务上测试并使用了Mydump ...

  8. mydumper原理3

    Mydumper介绍 Mydumper是一个针对MySQL和Drizzle的高性能多线程备份和恢复工具.开发人员主要来自MySQL,Facebook,SkySQL公司.目前已经在一些线上使用了Mydu ...

  9. mydumper原理1

    http://www.cnblogs.com/linuxnote/p/3817698.html?utm_source=tuicool&utm_medium=referral mydumper介 ...

随机推荐

  1. python学习8-闭包、迭代器(转载)

    一.第一类对象: 函数名是一个变量,可以当普通变量使用,但它又是一个特殊的变量,与括号配合可以执行函数. 函数名的运用 1.单独打印是一个内存地址 2.可以给其他变量赋值 3.可以作为容器类变量的元素 ...

  2. spring利用cors处理跨域问题

    参考 http://blog.csdn.net/isea533/article/details/50449907 写的很全面 http://blog.csdn.net/a317560315/artic ...

  3. EditText属性

    来自http://mp.weixin.qq.com/s/Yncr0XZ4MCWZH2vzTVyYJw android:inputType=”none”android:inputType=”text”a ...

  4. 抽象工厂方法模式(Abstract Factory Pattern)

    Provide an interface for creating families of related or dependent objects without specifying their ...

  5. 第三章:ionic环境搭建之windows篇

    下面是在windows操作系统上面安装ionic的步骤,已经在Windows 10/ 7/ XP下面通过验证. 安装JDK 1.1 下载(http://www.oracle.com/technetwo ...

  6. 《springcloud 四》服务保护机制

    服务保护机制SpringCloud Hystrix 微服务高可用技术 大型复杂的分布式系统中,高可用相关的技术架构非常重要. 高可用架构非常重要的一个环节,就是如何将分布式系统中的各个服务打造成高可用 ...

  7. Smart3D基础理论

    目录: 1. Smart3D发展进程 2. 硬件要求与建模原理 3. Smart3D建模优势 4.Smart3D的应用领域 5. Smart3D的软件组成 6. Samrt3D主控台概述 1. Sma ...

  8. Linux文本处理工具

    Linux文本处理工具 Linux中熟练的使用文本处理工具非常的重要, 因为Linux在设计的时候是采用一切皆文件的哲学的, 甚至连计算机中的配置也都使用伪文件系统来表示, 要查询里面的内容就是对文件 ...

  9. HRBUST 1909——理工门外的树——————【离线处理,差分前缀和】

    理工门外的树 Time Limit: 1000 MS Memory Limit: 32768 KB 64-bit integer IO format: %lld , %llu Java class n ...

  10. 【Linux相识相知】rpm包管理

    我们日常在使用Windows的时候,如果要安装某个软件,最简单的方法就是在程序包的官网直接下载软件包到本地,一般是以.exe或者.msi格式的文件,然后一直下一步下一步就能安装成功了,但是在使用lin ...