1. Introduction to mydumper
Mydumper is a high-performance multi-threaded backup and recovery tool for MySQL and Drizzle.
Mydumper's main features: multi-threaded backup
written in lightweight C language
, multiple backup files will be generated after backup,
transactional and non-transactional table consistent snapshots (applicable to version 0.2.2 and above),
fast file compression,
support for exporting
multiple binlogs Thread recovery (applicable to version 0.2.1 and above) works
as a daemon, timed snapshot and continuous binary log (applicable to version 0.5.0 and above)
Open source (GNU GPLv3)
2. Download and install
2.1 Download
wget https://github.com/maxbube/mydumper/releases/download/v0.9.5/mydumper-0.9.5-2.el7.x86_64.rpm
2.2 Installation
Install dependencies first
yum -y install glib2-devel zlib-devel pcre-devel
Install mydumper again
yum -y install mydumper-0.9.5-2.el7.x86_64.rpm
View version
[root@host-137 ~]# mydumper -V
mydumper 0.9.5, built against MySQL 5.7.21-21
3. Mydumper parameter explanation
-B, --database 要备份的数据库,不指定则备份所有库
-T, --tables-list 需要备份的表,名字用逗号隔开
-o, --outputdir 备份文件输出的目录
-s, --statement-size 生成的insert语句的字节数,默认1000000
-r, --rows 将表按行分块时,指定的块行数,指定这个选项会关闭 --chunk-filesize
-F, --chunk-filesize 将表按大小分块时,指定的块大小,单位是 MB
-c, --compress 压缩输出文件
-e, --build-empty-files 如果表数据是空,还是产生一个空文件(默认无数据则只有表结构文件)
-x, --regex 是同正则表达式匹配 'db.table'
-i, --ignore-engines 忽略的存储引擎,用都厚分割
-m, --no-schemas 不备份表结构
-k, --no-locks 不使用临时共享只读锁,使用这个选项会造成数据不一致
--less-locking 减少对InnoDB表的锁施加时间(这种模式的机制下文详解)
-l, --long-query-guard 设定阻塞备份的长查询超时时间,单位是秒,默认是60秒(超时后默认mydumper将会退出)
--kill-long-queries 杀掉长查询 (不退出)
-b, --binlogs 导出binlog
-D, --daemon 启用守护进程模式,守护进程模式以某个间隔不间断对数据库进行备份
-I, --snapshot-interval dump快照间隔时间,默认60s,需要在daemon模式下
-L, --logfile 使用的日志文件名(mydumper所产生的日志), 默认使用标准输出
--tz-utc 跨时区是使用的选项,不解释了
--skip-tz-utc 同上
--use-savepoints 使用savepoints来减少采集metadata所造成的锁时间,需要 SUPER 权限
--success-on-1146 Not increment error count and Warning instead of Critical in case of table doesn't exist
-h, --host 连接的主机名
-u, --user 备份所使用的用户
-p, --password 密码
-P, --port 端口
-S, --socket 使用socket通信时的socket文件
-t, --threads 开启的备份线程数,默认是4
-C, --compress-protocol 压缩与mysql通信的数据
-V, --version 显示版本号
-v, --verbose 输出信息模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默认为 2
4. Myloader parameter explanation
-d, --directory 备份文件的文件夹
-q, --queries-per-transaction 每次事物执行的查询数量,默认是1000
-o, --overwrite-tables 如果要恢复的表存在,则先drop掉该表,使用该参数,需要备份时候要备份表结构
-B, --database 需要还原的数据库
-e, --enable-binlog 启用还原数据的二进制日志
-h, --host 主机
-u, --user 还原的用户
-p, --password 密码
-P, --port 端口
-S, --socket socket文件
-t, --threads 还原所使用的线程数,默认是4
-C, --compress-protocol 压缩协议
-V, --version 显示版本
-v, --verbose 输出模式, 0 = silent, 1 = errors, 2 = warnings, 3 = info, 默认为2
5. Back up the specified database
5.1 Create a backup directory
mkdir -p /data/backup/mysql
5.2 Use mydumper to backup baidu database
mydumper -u root -p 456 -B baidu -o /data/backup/mysql
5.3 View the files in the backup directory
[root@host-137 ~]# tree /data/backup/mysql/
/data/backup/mysql/
├── baidu.dupan-schema.sql 表结构文件
├── baidu.dupan.sql 表数据文件
├── baidu-schema-create.sql 库结构文件
└── metadata 备份时间记录
6. Restore the specified library
6.1 Delete baidu database
MariaDB [baidu]> drop database baidu;
Query OK, 1 row affected (0.00 sec)
验证删除成功
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
6.2 myloader restore baidu database
myloader -u root -p 456 -B baidu -d /data/backup/mysql
6.3 Verify successful recovery
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| baidu |
| mysql |
| performance_schema |
| test |
+--------------------+
7 rows in set (0.00 sec)