系统:centos5.9-x86_64
版本:mydumper-0.5.2 LINK:下载
官网:https://launchpad.net/mydumper/
依赖包:
yum install pcre-devel.x86_64 crypt*-devel zlib.x86_64 -y |
安装(根据mysql安装路径指定,安装不同版本mysql,要输出mysql的lib到/etc/ld.so.conf.d/)
tar zxvf mydumper-0.5.2.tar.gz cd mydumper-0.5.2 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mydumper -DMYSQL_ADD_INCLUDE_DIR=/usr/local/mysql-35/include -DMYSQL_CONFIG=/usr/local/mysql-35/bin/mysql_configmakemake install |
备份
mkdir -p /bak/mydumper/dbname/usr/local/mydumper/bin/mydumper -B dbname -o /bak/mydumper/dbname -u root -p your_passwd -S /tmp/mysql.sock -t 8 -v 3 |
还原
/usr/local/mydumper/bin/myloader -d /bak/mydumper/dbname / -o -B dbname -u root -p your_passwd -S /tmp/mysql.sock -t 8 -P 3306 -v 3 |
mydumper参数介绍:
-B, –database 需要备份的库
-T, –tables-list 需要备份的表,用,分隔
-o, –outputdir 输出目录
-s, –statement-size Attempted size of INSERT statement in bytes, default 1000000
-r, –rows 试图分裂成很多行块表
-c, –compress 压缩输出文件
-e, –build-empty-files 即使表没有数据,还是产生一个空文件
-x, –regex 支持正则表达式
-i, –ignore-engines 忽略的存储引擎,用,分隔
-m, –no-schemas 不导出表结构
-k, –no-locks 不执行临时共享读锁 警告:这将导致不一致的备份
-l, –long-query-guard 长查询,默认60s
–kill-long-queries kill掉长时间执行的查询(instead of aborting)
-b, –binlogs 导出binlog
-D, –daemon 启用守护进程模式
-I, –snapshot-interval dump快照间隔时间,默认60s,需要在daemon模式下
-L, –logfile 日志文件
-h, –host
-u, –user
-p, –password
-P, –port
-S, –socket
-t, –threads 使用的线程数,默认4
-C, –compress-protocol 在mysql连接上使用压缩
-V, –version
-v, –verbose 更多输出, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
myloader参数介绍:
-d, –directory 导入备份目录
-q, –queries-per-transaction 每次执行的查询数量, 默认1000
-o, –overwrite-tables 如果表存在删除表
-B, –database 需要还原的库
-e, –enable-binlog 启用二进制恢复数据
-h, –host
-u, –user
-p, –password
-P, –port
-S, –socket
-t, –threads 使用的线程数量,默认4
-C, –compress-protocol 连接上使用压缩
-V, –version
-v, –verbose 更多输出, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
mydumper输出文件:
metadata:元数据 记录备份开始和结束时间,以及binlog日志文件位置。
table data:每个表一个文件
table schemas:表结构文件
binary logs: 启用–binlogs选项后,二进制文件存放在binlog_snapshot目录下
daemon mode:
在这个模式下,有五个目录0,1,binlogs,binlog_snapshot,last_dump。备份目录是0和1,间隔备份,如果mydumper因某种原因失败而仍然有一个好的快照,当快照完成后,last_dump指向该备份。
=#一个可能的make ERROR报错#=
# makeScanning dependencies of target mydumper[ 20%] Building C object CMakeFiles/mydumper.dir/mydumper.c.o[ 40%] Building C object CMakeFiles/mydumper.dir/binlog.c.o In file included from /root/src/mydumper-0.5.2/binlog.c:27:/usr/local/mysql/include/sql_common.h:26:18: error: hash.h: No such file or directory In file included from /root/src/mydumper-0.5.2/binlog.c:27:/usr/local/mysql/include/sql_common.h:37: error: expected specifier-qualifier-list before ‘HASH’make[2]: *** [CMakeFiles/mydumper.dir/binlog.c.o] Error 1make[1]: *** [CMakeFiles/mydumper.dir/all] Error 2make: *** [all] Error 2 |
版本:mysql-5.6.x
复制编译完成mysql源代码包内的include/hash.h至mysql安装目录下的include文件夹内即可。
=#一个可能的执行 ERROR报错#=
/usr/local/mydumper/bin/myloader: relocation error: /usr/local/mydumper/bin/myloader: symbol mysql_init, version libmysqlclient_18 not defined in file libmysqlclient.so.18 with link time reference |
find发现/usr/lib64/mysql/下面也存在libmysqlclient.so.18,删掉,用安装的mysql替换,即可解决
cp -f /usr/local/mysql/lib/libmysqlclient.so.18.0.0 /usr/lib64/mysql/cp -f /usr/local/mysql/bin/mysql_config /usr/lib64/mysql/