技术分享 | MySQL史上最快逻辑备份工具
来源:SegmentFault
2023-01-26 17:05:00
0浏览
收藏
亲爱的编程学习爱好者,如果你点开了这篇文章,说明你对《技术分享 | MySQL史上最快逻辑备份工具》很感兴趣。本篇文章就来给大家详细解析一下,主要介绍一下MySQL,希望所有认真读完的童鞋们,都有实质性的提高。
作者:洪斌
爱可生南区负责人兼技术服务总监,MySQL ACE,擅长数据库架构规划、故障诊断、性能优化分析,实践经验丰富,帮助各行业客户解决 MySQL 技术问题,为金融、运营商、互联网等行业客户提供 MySQL 整体解决方案。
本文来源:转载自公众号-玩转MySQL
*爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。
MySQL Shell 8.0.21 增加了一种新的逻辑备份恢复方法,有更快的备份恢复效率,支持zstd实时压缩,支持分块并行导出,load data并行导入,还能备份到OCI的对象存储。
- util.dumpInstance() 用于备份整个实例
- util.dumpSchemas() 用于备份指定schema
- util.loadDump() 用于恢复备份
做了个对比测试,在零负载下mysql配置参数不变,备份/恢复相同schema,其中混合了大表和小表,看下这几种方式的实际效果如何。
对比结果

结论
- mysql shell
使用默认参数zstd压缩+32M chunk并行导出,恢复时单表可以并行load data,其备份和恢复速度均优于非压缩+非分块。
测试中发现,若禁用压缩,也会禁用分块。 - mysqldump
备份和恢复都是单线程执行,不压缩的备份效率更快,zstd的实时备份速度比gzip更快,恢复速度最慢。
- mysqlpump
备份支持并行速度也很快,但是单线程恢复是硬伤。
- mydumper
默认用gzip协议,备份速度与mysqldump基本一样,看来瓶颈在压缩上。 在非压缩非分块备份速度会更快。 恢复速度中等,单表无法并行。
综合上述测试结果,mysql shell新的备份恢复方式是最快的,得益于使用了zstd实时压缩算法,备份恢复均可以并行,对于单个大表也可以并行。
下面是部分测试过程供参考:
MySQLShell
utli.dumpSchemas/utli.loadDump
- 备份
Acquiring global read lock All transactions have been started Locking instance for backup Global read lock has been released Writing global DDL files Preparing data dump for table `test`.`customer1` Writing DDL for schema `test` Writing DDL for table `test`.`sbtest1` Writing DDL for table `test`.`customer1` Writing DDL for table `test`.`sbtest10` Data dump for table `test`.`customer1` will be chunked using column `c_w_id` Preparing data dump for table `test`.`sbtest1` Data dump for table `test`.`sbtest1` will be chunked using column `id` Preparing data dump for table `test`.`sbtest10` Data dump for table `test`.`sbtest10` will be chunked using column `id` Preparing data dump for table `test`.`sbtest2` Data dump for table `test`.`sbtest2` will be chunked using column `id` Preparing data dump for table `test`.`sbtest4` Data dump for table `test`.`sbtest4` will be chunked using column `id` Preparing data dump for table `test`.`sbtest6` Data dump for table `test`.`sbtest6` will be chunked using column `id` Preparing data dump for table `test`.`sbtest8` Data dump for table `test`.`sbtest8` will be chunked using column `id` Running data dump using 4 threads. NOTE: Progress information uses estimated values and may not be accurate. Writing DDL for table `test`.`sbtest2` Writing DDL for table `test`.`sbtest4` Writing DDL for table `test`.`sbtest6` Writing DDL for table `test`.`sbtest8` Data dump for table `test`.`customer1` will be written to 3 files Data dump for table `test`.`sbtest10` will be written to 1 file Data dump for table `test`.`sbtest2` will be written to 1 file Data dump for table `test`.`sbtest4` will be written to 1 file Data dump for table `test`.`sbtest6` will be written to 1 file Data dump for table `test`.`sbtest8` will be written to 1 file Data dump for table `test`.`sbtest1` will be written to 160 files 1 thds dumping - 98% (10.46M rows / ~10.62M rows), 589.52K rows/s, 115.55 MB/s uncompressed, 51.66 MB/s compressed Duration: 00:00:18s Schemas dumped: 1 Tables dumped: 7 Uncompressed data size: 2.06 GB Compressed data size: 922.35 MB Compression ratio: 2.2 Rows written: 10464999 Bytes written: 922.35 MB Average uncompressed throughput: 109.46 MB/s Average compressed throughput: 48.97 MB/s
- 恢复
util.loadDump("test1") Loading DDL and Data from 'instance' using 4 threads. Target is MySQL 8.0.21. Dump was produced from MySQL 8.0.21 Checking for pre-existing objects... Executing common preamble SQL Executing DDL script for schema `test` Executing DDL script for `test`.`sbtest1` Executing DDL script for `test`.`sbtest4` Executing DDL script for `test`.`sbtest2` Executing DDL script for `test`.`sbtest8` Executing DDL script for `test`.`sbtest10` Executing DDL script for `test`.`sbtest6` Executing DDL script for `test`.`customer1` ... [Worker000] test@sbtest1@158.tsv.zst: Records: 65736 Deleted: 0 Skipped: 0 Warnings: 0 Executing common postamble SQL 168 chunks (10.46M rows, 2.06 GB) for 7 tables in 1 schemas were loaded in 1 min 26 sec (avg throughput 23.97 MB/s)
mysqldump
- 备份
/usr/bin/time mysqldump -umsandbox -pmsandbox -h127.0.0.1 -P8021 test | gzip > db.sql.gz mysqldump: [Warning] Using a password on the command line interface can be insecure. 169.40 real 24.65 user 1.34 sys
- 恢复
/usr/bin/time gzip -d
mysqlpump
- 备份
/usr/bin/time mysqlpump --default-parallelism=4 -umsandbox -pmsandbox -h127.0.0.1 -P8021 test | gzip > db2.sql.gz Dump progress: 6/7 tables, 10421749/10406264 rows Dump completed in 185352 185.50 real 31.18 user 6.34 sys
- 恢复
/usr/bin/time gzip -d
mydumper/myloader
- 备份
/usr/bin/time mydumper -u msandbox -p msandbox -h 127.0.0.1 -P 8021 -B test -t 4 -v 3 -c -o dumper ** Message: 21:44:55.958: Connected to a MySQL server ** Message: 21:44:56.319: Started dump at: 2020-07-24 21:44:56 ** Message: 21:44:56.341: Written master status ** Message: 21:44:56.420: Thread 1 connected using MySQL connection ID 22 ** Message: 21:44:56.537: Thread 2 connected using MySQL connection ID 23 ** Message: 21:44:56.651: Thread 3 connected using MySQL connection ID 24 ** Message: 21:44:56.769: Thread 4 connected using MySQL connection ID 25 ** Message: 21:44:56.878: Non-InnoDB dump complete, unlocking tables ** Message: 21:44:56.878: Thread 4 dumping data for `test`.`sbtest10` ** Message: 21:44:56.878: Thread 1 dumping data for `test`.`customer1` ** Message: 21:44:56.878: Thread 3 dumping data for `test`.`sbtest1` ** Message: 21:44:56.878: Thread 2 dumping data for `test`.`sbtest2` ** Message: 21:44:57.139: Thread 2 dumping data for `test`.`sbtest4` ** Message: 21:44:57.143: Thread 4 dumping data for `test`.`sbtest6` ** Message: 21:44:57.396: Thread 2 dumping data for `test`.`sbtest8` ** Message: 21:44:57.398: Thread 4 dumping schema for `test`.`customer1` ** Message: 21:44:57.409: Thread 4 dumping schema for `test`.`sbtest1` ** Message: 21:44:57.419: Thread 4 dumping schema for `test`.`sbtest10` ** Message: 21:44:57.430: Thread 4 dumping schema for `test`.`sbtest2` ** Message: 21:44:57.441: Thread 4 dumping schema for `test`.`sbtest4` ** Message: 21:44:57.453: Thread 4 dumping schema for `test`.`sbtest6` ** Message: 21:44:57.464: Thread 4 dumping schema for `test`.`sbtest8` ** Message: 21:44:57.475: Thread 4 shutting down ** Message: 21:44:57.636: Thread 2 shutting down ** Message: 21:45:03.706: Thread 1 shutting down ** Message: 21:47:40.297: Thread 3 shutting down ** Message: 21:47:40.307: Finished dump at: 2020-07-24 21:47:40 164.54 real 167.58 user 2.28 sys
注:使用的并行备份线程数与dumpSchema相同。
- 恢复
/usr/bin/time myloader -u msandbox -p msandbox -h 127.0.0.1 -P 8021 -B test -t 4 -v 3 -d dumper/ ** Message: 23:54:39.961: 4 threads created ** Message: 23:54:39.973: Creating table `test`.`sbtest4` ** Message: 23:54:40.055: Creating table `test`.`sbtest10` ** Message: 23:54:40.127: Creating table `test`.`customer1` ** Message: 23:54:40.201: Creating table `test`.`sbtest8` ** Message: 23:54:40.273: Creating table `test`.`sbtest2` ** Message: 23:54:40.346: Creating table `test`.`sbtest6` ** Message: 23:54:40.423: Creating table `test`.`sbtest1` ** Message: 23:54:40.488: Thread 2 restoring `test`.`sbtest2` part 0 ** Message: 23:54:40.488: Thread 3 restoring `test`.`sbtest6` part 0 ** Message: 23:54:40.488: Thread 4 restoring `test`.`sbtest8` part 0 ** Message: 23:54:40.488: Thread 1 restoring `test`.`sbtest4` part 0 ** Message: 23:54:40.833: Thread 2 restoring `test`.`sbtest1` part 0 ** Message: 23:54:40.833: Thread 4 restoring `test`.`sbtest10` part 0 ** Message: 23:54:40.834: Thread 3 restoring `test`.`customer1` part 0 ** Message: 23:54:40.834: Thread 1 shutting down ** Message: 23:54:41.070: Thread 4 shutting down ** Message: 23:54:50.407: Thread 3 shutting down ** Message: 23:57:46.425: Thread 2 shutting down
文中关于mysql的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《技术分享 | MySQL史上最快逻辑备份工具》文章吧,也可关注golang学习网公众号了解相关技术文章。
版本声明
本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除

- 上一篇
- MySQL 配置基础

- 下一篇
- mysql中IS NULL、IS NOT NULL不能走索引?
评论列表
-
- 整齐的小鸽子
- 这篇技术文章真及时,很详细,很棒,码起来,关注老哥了!希望老哥能多写数据库相关的文章。
- 2023-04-05 01:45:00
-
- 文艺的路人
- 这篇技术文章真及时,up主加油!
- 2023-03-16 03:08:16
-
- yajie
- 好细啊,收藏了,感谢作者的这篇技术贴,我会继续支持!
- 2023-03-09 05:13:43
-
- 聪慧的小丸子
- 写的不错,一直没懂这个问题,但其实工作中常常有遇到...不过今天到这,看完之后很有帮助,总算是懂了,感谢up主分享技术文章!
- 2023-01-27 10:08:38
查看更多
最新文章
-
- 数据库 · MySQL | 27分钟前 |
- MySQL缓存优化技巧分享
- 216浏览 收藏
-
- 数据库 · MySQL | 34分钟前 |
- MySQL入门教程:零基础学数据库操作
- 319浏览 收藏
-
- 数据库 · MySQL | 2小时前 |
- MySQL数据备份方法与工具推荐
- 291浏览 收藏
-
- 数据库 · MySQL | 4小时前 |
- MySQL中AS的别名用法解析
- 261浏览 收藏
-
- 数据库 · MySQL | 4小时前 |
- MySQL中IF函数使用详解
- 426浏览 收藏
-
- 数据库 · MySQL | 4小时前 |
- 主键与唯一键区别,如何选型更合理
- 374浏览 收藏
-
- 数据库 · MySQL | 4小时前 |
- HAVING与WHERE区别详解及使用场景
- 369浏览 收藏
-
- 数据库 · MySQL | 7小时前 |
- MySQL建表语法详解与实例演示
- 176浏览 收藏
-
- 数据库 · MySQL | 9小时前 |
- MySQL字符集设置全攻略
- 499浏览 收藏
-
- 数据库 · MySQL | 22小时前 |
- MySQL中HAVING和WHERE的区别
- 186浏览 收藏
-
- 数据库 · MySQL | 1天前 |
- MySQL中文语言包安装配置指南
- 312浏览 收藏
-
- 数据库 · MySQL | 1天前 |
- MySQL数据备份4种方法保障安全
- 103浏览 收藏
查看更多
课程推荐
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 511次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 498次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 484次学习
查看更多
AI推荐
-
- 千音漫语
- 千音漫语,北京熠声科技倾力打造的智能声音创作助手,提供AI配音、音视频翻译、语音识别、声音克隆等强大功能,助力有声书制作、视频创作、教育培训等领域,官网:https://qianyin123.com
- 170次使用
-
- MiniWork
- MiniWork是一款智能高效的AI工具平台,专为提升工作与学习效率而设计。整合文本处理、图像生成、营销策划及运营管理等多元AI工具,提供精准智能解决方案,让复杂工作简单高效。
- 170次使用
-
- NoCode
- NoCode (nocode.cn)是领先的无代码开发平台,通过拖放、AI对话等简单操作,助您快速创建各类应用、网站与管理系统。无需编程知识,轻松实现个人生活、商业经营、企业管理多场景需求,大幅降低开发门槛,高效低成本。
- 172次使用
-
- 达医智影
- 达医智影,阿里巴巴达摩院医疗AI创新力作。全球率先利用平扫CT实现“一扫多筛”,仅一次CT扫描即可高效识别多种癌症、急症及慢病,为疾病早期发现提供智能、精准的AI影像早筛解决方案。
- 179次使用
-
- 智慧芽Eureka
- 智慧芽Eureka,专为技术创新打造的AI Agent平台。深度理解专利、研发、生物医药、材料、科创等复杂场景,通过专家级AI Agent精准执行任务,智能化工作流解放70%生产力,让您专注核心创新。
- 191次使用
查看更多
相关文章
-
- golang MySQL实现对数据库表存储获取操作示例
- 2022-12-22 499浏览
-
- 搞一个自娱自乐的博客(二) 架构搭建
- 2023-02-16 244浏览
-
- B-Tree、B+Tree以及B-link Tree
- 2023-01-19 235浏览
-
- mysql面试题
- 2023-01-17 157浏览
-
- MySQL数据表简单查询
- 2023-01-10 101浏览