MySQL自身的mysqldump工具支持单线程工作,依次一个个导出多个表,没有一个并行的机,这就使得它无法迅速的备份数据。
Mydumper作为一个实用工具,能够良好支持多线程工作,可以并行的多线程的从表中读入数据并同时写到不同的文件里,这使得它在处理速度方面快于传统的mysqldump。其特征之一是在处理过程中需要对列表加以锁定,因此如果我们需要在工作时段执行备份工作,那么会引起DML阻塞。但一般现在的MySQL都有主从,备份也大部分在从上进行,所以锁的问题可以不用考虑。这样,mydumper能更好的完成备份任务。
1. 多线程备份
2. 因为是多线程逻辑备份,备份后会生成多个备份文件
3. 备份时对MyISAM表施加FTWRL(FLUSH TABLES WITH READ LOCK),会阻塞DML语句
4. 保证备份数据的一致性
5. 支持文件压缩
6. 支持导出binlog
7. 支持多线程恢复
8. 支持以守护进程模式工作,定时快照和连续二进制日志
9. 支持将备份文件切块
# git clone https://github.com/maxbube/mydumper
# cd mydumper
# less README.md (查看帮助文档,里面说明了如何编译安装以及依赖包)
# yum install glib2-devel zlib-devel pcre-devel openssl-devel cmake
# cmake
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/mydumper
** 出现Configuring done和Generating done说明cmake成功了,如果有报错,请查看详细的屏幕输出日志
# make -j 4
# make install (会把mydumper和myloader安装在/usr/local/bin/目录下)
# mydumper
# mydumper --help
mydumper: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory (报错说明找不到这个共享库)
# ldd /usr/local/bin/mydumper
linux-vdso.so.1 => (0x00007ffe2aebb000)
libmysqlclient.so.20 => not found
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fdf6d0a0000)
libm.so.6 => /lib64/libm.so.6 (0x00007fdf6ce1c000)
librt.so.1 => /lib64/librt.so.1 (0x00007fdf6cc14000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fdf6ca0f000)
libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007fdf6c6f8000)
libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007fdf6c4f4000)
libpcre.so.0 => /lib64/libpcre.so.0 (0x00007fdf6c2c6000)
libz.so.1 => /lib64/libz.so.1 (0x00007fdf6c0b0000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fdf6bdaa000)
libc.so.6 => /lib64/libc.so.6 (0x00007fdf6ba15000)
/lib64/ld-linux-x86-64.so.2 (0x00007fdf6d2c9000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fdf6b7ff000)
# LD_DEBUG=libs /usr/local/bin/mydumper -v
1987: find library=libmysqlclient.so.20 [0]; searching
1987: search cache=/etc/ld.so.cache
1987: search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64 (system search path)
1987: trying file=/lib64/tls/x86_64/libmysqlclient.so.20
1987: trying file=/lib64/tls/libmysqlclient.so.20
1987: trying file=/lib64/x86_64/libmysqlclient.so.20
1987: trying file=/lib64/libmysqlclient.so.20
1987: trying file=/usr/lib64/tls/x86_64/libmysqlclient.so.20
1987: trying file=/usr/lib64/tls/libmysqlclient.so.20
1987: trying file=/usr/lib64/x86_64/libmysqlclient.so.20
1987: trying file=/usr/lib64/libmysqlclient.so.20
1987:
/usr/local/bin/mydumper: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
# locate libmysqlclient.so.20
# ll /usr/local/mysql/lib/
# cp /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib/
# ldconfig
# ldd /usr/local/bin/mydumper
# 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, --omit-from-file File containing a list of database.table entries to skip, one per line (skips before applying 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
-N, --insert-ignore Dump rows with INSERT IGNORE
-m, --no-schemas Do not dump table schemas with the data
-d, --no-data Do not dump table data