0简介
mydumper 是一款社区开源的逻辑备份工具。该工具主要由 C 语言编写,目前由 MySQL 、Facebook 等公司人员开发维护。
mydumper
负责导出 MySQL 数据库的一致备份myloader
从 mydumper 读取备份,连接到目标数据库并导入备份。
1 安装
1.1下载
下载地址:Releases · mydumper/mydumper (github.com),此网站有各个版本的安装包,目前最新版本是v0.14.0-2
可以先下载后传到服务器,也可以使用wget命令来直接下载。
wget https://github.com/mydumper/mydumper/releases/download/v0.14.0-2/mydumper-0.14.0-2.el7.x86_64.rpm
1.2安装
安装依赖:
# ubuntu yum install glib2-devel mysql-devel gcc gcc-c++ zlib-devel pcre-devel openssl-devel libicu-dev cmake -y # centos8 yum install glib2-devel mysql-devel gcc gcc-c++ zlib-devel pcre-devel openssl-devel cmake -y
安装rpm包
rpm -ivh mydumper-0.14.0-2.el7.x86_64.rpm
也可以直接安装线上版本
yum install wget https://github.com/mydumper/mydumper/releases/download/v0.14.0-2/mydumper-0.14.0-2.el7.x86_64.rpm
1.3卸载
[root@gip 3308]# yum list installed |grep mydumper mydumper.x86_64 0.14.0-2 installed [root@gip 3308]# yum remove mydumper.x86_64
2 使用
备份命令 mydumper
常用重要选项
Filter Options
-x, --regex Regular expression for 'db.table' matching -T, --tables-list Comma delimited table list to dump (does not exclude regex option). Table name must include database name.
-B, --database Database to dump
-O, --omit-from-file File containing a list of database.table entries to skip
Lock Options
-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.
If long query running found
-l, --long-query-guard Set long query timer in seconds, default 60
-K, --kill-long-queries Kill long running queries (instead of aborting)
Job Options
-r, --rows Try to split tables into chunks of this many rows.
--split-partitions Dump partitions into separate files. This options overrides the --rows option for partitioned tables.
Objects Options
-m, --no-schemas Do not dump table schemas with the data and triggers
-d, --no-data Do not dump table data
-G, --triggers Dump triggers. By default, it do not dump triggers
-E, --events Dump events. By default, it do not dump events
-R, --routines Dump stored procedures and functions. By default, it do not dump stored procedures nor functions
--views-as-tables Export VIEWs as they were tables
-W, --no-views Do not dump VIEWs
Application Options:
-o, --outputdir Directory to output files to
--stream It will stream over STDOUT once the files has been written. Since v0.12.7-1, accepts NO_DELETE, NO_STREAM_AND_NO_DELETE and TRADITIONAL which is the default value
-L, --logfile Log file name to use, by default stdout is used
--disk-limits Set the limit to pause and resume if determines there is no enough disk space.Accepts values like: '<resume>:<pause>' in MB.For instance: 100:500 will pause when there is only 100MB free and willresume if 500MB are available
-t, --threads Number of threads to use, default 4
导出后文件命名规则大致如下:
dbname-schema-create.sql:建库语句。 dbname-schema-post.sql:包含事件、存储过程及函数创建语句(若存在则有该文件)。 dbname.tbname.metadata:记录这个表的行数。 dbname.tbname-schema.sql:此表的创建语句。 dbname.tbname-schema-triggers.sql:创建触发器语句(若该表存在触发器 则有此文件)。 dbname.tbname.sql:该表的插入数据语句(若该表为空 则不存在此文件)。 dbname.viewname-schema.sql:创建视图语句(只列举出视图字段)。 dbname.viewname-schema-view.sql:创建视图的真正语句。 metadata:记录开始及结束备份的时间以及二进制日志位置。
使用举例:
备份指定表
备份指定库
备份所有表结构
备份所有表数据
备份整个实例
172.17.140.158 -
导入命令myloader
使用举例
3 特点
- 支持多线程导出数据,速度更快。
- 支持一致性备份。
- 支持将导出文件压缩,节约空间。
- 支持多线程恢复。
- 支持以守护进程模式工作,定时快照和连续二进制日志。
- 支持按照指定大小将备份文件切割。
- 数据与建表语句分离。
标签:总结,mydumper,dump,--,备份,devel,学习,dbname From: https://www.cnblogs.com/JennyYu/p/17080154.html