12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
mysql数据库 时间:2024-12-25 09:56:44
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
mydumper简介:由percona公司的Max Bubenick与facebook公司的Domas Mituzas共同维护开发,也是个10年历史的工具了,与同为逻辑备份的mysqldump工具而言,其特性在于多线程并行备份,
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
mydumper
简介:
由percona公司的Max Bubenick与facebook公司的Domas Mituzas共同维护开发,也是个10年历史的工具了,与同为逻辑备份的mysqldump工具而言,其特性在于多线程并行备份,与官方同类型的mysqlpump相比,其优点在于一张表可以分到好几个线程上进行备份。
安装:
很多博客都推荐使用编译的方式进行安装 ,在这里点一下坑,由于mydumper依赖了 glib2-devel mysql-devel zlib-devel pcre-devel openssl-devel等第三方库,而这些库之前并没有按系统默认方式安装到各个默认位置,那么将会产生编译安装的连锁指定编译位置的问题。我在Cent7系统上安装时,就遇到很多编译不通过或者编译后使用报错的问题,检查环境后发现系统运维的同事使用编译安装的方式安装了MySQL 5.6与pcre库。后面我尝试使用yum安装库后,还是无法排除问题。 在这里我推荐使用开发者编译好的rpm包进行安装,配合yum可以自动补齐依赖,避免很多坑。 地址:https://github.com/maxbube/mydumper/releases,请根据自己的系统类型选择下载版本。`yum -y install https://github.com/maxbube/mydumper/releases/download/v0.9.3/mydumper-0.9.3-41.el7.x86_64.rpm`
使用:
$mydumper --helpUsage:mydumper [OPTION...] multi-threaded MySQL dumpingHelp Options:-?, --helpShow help optionsApplication Options:-B, --databaseDatabase 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-sizeAttempted size of INSERT statement in bytes, default 1000000-r, --rowsTry to split tables into chunks of this many rows. This option turns off --chunk-filesize-F, --chunk-filesizeSplit tables into chunks of this output file size. This value is in MB-c, --compressCompress 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-enginesComma delimited list of storage engines to ignore-m, --no-schemasDo not dump table schemas with the data-d, --no-data Do not dump table data-G, --triggersDump triggers-E, --eventsDump events-R, --routinesDump stored procedures and functions-W, --no-viewsDo not dump VIEWs-k, --no-locksDo not execute the temporary shared read lock.WARNING: This will cause inconsistent backups--no-backup-locks Do not use Percona backup locks--less-lockingMinimize locking time on InnoDB tables.-l, --long-query-guardSet long query timer in seconds, default 60-K, --kill-long-queries Kill long running queries (instead of aborting)-D, --daemonEnable daemon mode-I, --snapshot-interval Interval between each dump snapshot (in minutes), requires --daemon, default 60-L, --logfile Log file name to use, by default stdout is used--tz-utcSET 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-savepointsUse savepoints to reduce metadata locking issues, needs SUPER privilege--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-onlyTransactional consistency only--complete-insert Use complete INSERT statements that include column names-h, --hostThe host to connect to-u, --userUsername with the necessary privileges-p, --passwordUser password-P, --portTCP/IP port to connect to-S, --socketUNIX domain socket file to use for connection-t, --threads Number of threads to use, default 4-C, --compress-protocol Use compression on the MySQL connection-V, --version Show the program version and exit-v, --verbose Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2--defaults-file Use a specific defaults file
这里给出我最常用的备份方式:
mydumper -h 192.168.1.109 -P 3109 -u root -p 123456 -G -E -R -t 4 -c -o /data/bak/mysql/3109
说明:-h 指定地址
-P 指定备份端口 -u 指定备份用户 -p 密码 -G 备份触发器 -E备份定时事件 -R备份存储过程和函数 -t备份时并发的线程数(不包含备份主线程) -c对备份文件进行压缩(gz方式) -o指定备份存储位置
原理与过程:
与mysqldump工具类似,先FTWRL(flush table with read lock),查询自己本身的事务执行位置(show master status),然后开启一个一致性快照事务,再启动若干个子线程分别开启一致性可重复读快照事务,使用子线程开启事务并读取数据和视图,函数,存储过程,定时事件等。由于实例中可能有非事务型表的存在,为保持一致性,待各个子线程全部备份完非事务型的表后才会释放FTWRL。这里重点说明下`--trx-consistency-only`参数,很多博客都是粗粗点过甚至不翻译。上一步中我们说到mydumper为了获取整个实例级别的一致性备份,会在开始备份时加上FTWRL,待各个线程都备份完非事务表后,才会释放FTWRL。这是考虑到5.7及之前的版本中mysql库的部分表是MyISAM引擎,不具备事务特性,或者业务上还存在非事务表。但8.0之后的版本中mysql库全部改成了InnoDB引擎,或者用户选择不备份mysql库,或者实例中一张非事务表都没有,这时mydumper会在创建完所有子线程并分别开启一致性可重复读快照事务后就释放FTWRL.因为这个时候根据事务特性已经可以保证备份一致了。若你确定没有备份非事务型表,或者没有备份mysql库,或者实例中非事务表的一致性无关紧要,在你非常介意备份时加的读锁对业务造成的影响的话,可以考虑加上`--trx-consistency-only`参数强制在创建完备的子线程后就释放锁,减小备份对业务造成的写堵塞
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19