mysqldump导入导出(MySQL官方导出工具mysqlpump的使用)
mysqldump导入导出
MySQL官方导出工具mysqlpump的使用简介
mysqlpump 是 mysqldump 的一个衍生,本身也参考了 mydumper 的思路,支持了并行导出数据,因此导出数据的效率比 mysqldump 会高很多。
使用介绍
mysqlpump 的绝大多数参数与 mysqldump 是一样的,整体的使用方法和 mysqldump 没有太多的差异。这里列出一部分 mysqlpump 中比较重要且常用的参数。
参数 |
说明 |
---|---|
--default-parallelism=# |
设置并行导出的并发度,与 single-transaction 冲突 |
--single-transaction |
创建一个单独的事务来导出所有的表 |
--exclude-databases=name |
导出时排除掉某些库,多个库以逗号分隔 |
--exclude-tables=name |
导出时排除掉某些表,多个表以逗号分隔 |
--include-databases=name |
导出时包含某些库,多个库以逗号分隔 |
--include-tables=name |
导出时包含某些表,多个表以逗号分隔 |
实际体验
这里对 mysqlpump 做一次简单的试用,目标实例选择 mysql 5.7,参数中同时采用了single-transaction和default-parallelism,试试看这个冲突的效果。
mysqlpump 侧的输出参考如下信息:
|
root@vm-64-10-debian:~# mysqlpump -h172.100.10.10 -uroot -p --single-transaction --default-parallelism=16 --set-gtid-purged=off -b sbtest > sbtest.sql dump progress: 0/1 tables, 250/987400 rows dump progress: 0/5 tables, 117250/3946600 rows dump progress: 1/5 tables, 258750/3946600 rows dump progress: 1/5 tables, 385500/3946600 rows dump progress: 1/5 tables, 516750/3946600 rows dump progress: 1/5 tables, 639250/3946600 rows dump progress: 1/5 tables, 757000/3946600 rows dump progress: 1/5 tables, 885000/3946600 rows dump progress: 1/5 tables, 1005750/3946600 rows dump progress: 1/5 tables, 1114250/3946600 rows dump progress: 1/5 tables, 1223250/3946600 rows dump progress: 2/5 tables, 1312500/3946600 rows dump progress: 2/5 tables, 1430750/3946600 rows dump progress: 2/5 tables, 1553000/3946600 rows dump progress: 2/5 tables, 1680250/3946600 rows dump progress: 2/5 tables, 1809500/3946600 rows dump progress: 2/5 tables, 1940750/3946600 rows dump progress: 2/5 tables, 2060000/3946600 rows dump progress: 2/5 tables, 2175250/3946600 rows dump progress: 2/5 tables, 2295250/3946600 rows dump progress: 3/5 tables, 2413500/3946600 rows dump progress: 3/5 tables, 2554500/3946600 rows dump progress: 3/5 tables, 2693500/3946600 rows dump progress: 3/5 tables, 2818750/3946600 rows dump progress: 3/5 tables, 2941500/3946600 rows dump progress: 4/5 tables, 3056000/3946600 rows dump progress: 4/5 tables, 3172750/3946600 rows dump progress: 4/5 tables, 3280000/3946600 rows dump progress: 4/5 tables, 3372000/3946600 rows dump progress: 4/5 tables, 3444750/3946600 rows dump completed in 126555 milliseconds |
可以看到当这两个参数同时启用的时候,mysqlpump 实际上还是在一个一个表的导出。single-transaction的优先级会高于default-parallelism。
去掉single-transaction再进行测试的时候,会发现一个比较有意思的现象,观察 mysql 的 processlist,会有如下结果:
|
mysql> show processlist; + ---------+------+--------------------+------+---------+------+-------------------+----------------------------------------------------+ | id | user | host | db | command | time | state | info | + ---------+------+--------------------+------+---------+------+-------------------+----------------------------------------------------+ | 2763496 | root | 172.100.10.10:49086 | null | query | 0 | starting | show processlist | | 2763585 | root | 172.100.10.10:49192 | null | sleep | 126 | | null | | 2763586 | root | 172.100.10.10:49194 | null | sleep | 126 | | null | | 2763587 | root |172.100.10.10:49196 | null | sleep | 126 | | null | | 2763588 | root | 172.100.10.10:49198 | null | sleep | 126 | | null | | 2763589 | root | 172.100.10.10:49200 | null | sleep | 126 | | null | | 2763590 | root | 172.100.10.10:49202 | null | sleep | 126 | | null | | 2763591 | root | 172.100.10.10:49204 | null | sleep | 126 | | null | | 2763592 | root | 172.100.10.10:49206 | null | sleep | 126 | | null | | 2763593 | root | 172.100.10.10:49208 | null | sleep | 126 | | null | | 2763594 | root | 172.100.10.10:49210 | null | sleep | 126 | | null | | 2763595 | root | 172.100.10.10:49212 | null | query | 125 | sending to client | select `id`,`k`,`c`,`pad` from `sbtest`.`sbtest5` | | 2763596 | root | 172.100.10.10:49214 | null | query | 125 | sending to client | select `id`,`k`,`c`,`pad` from `sbtest`.`sbtest4` | | 2763597 | root | 172.100.10.10:49216 | null | query | 125 | sending to client | select `id`,`k`,`c`,`pad` from `sbtest`.`sbtest3` | | 2763598 | root | 172.100.10.10:49218 | null | query | 125 | sending to client | select `id`,`k`,`c`,`pad` from `sbtest`.`sbtest2` | | 2763599 | root | 172.100.10.10:49220 | null | query | 125 | sending to client | select `id`,`k`,`c`,`pad` from `sbtest`.`sbtest1` | | 2763600 | root | 172.100.10.10:49222 | null | sleep | 125 | | null | | 2763601 | root | 172.100.10.10:49224 | null | sleep | 125 | | null | + ---------+------+--------------------+------+---------+------+-------------------+----------------------------------------------------+ 18 rows in set (0.00 sec) mysql> |
可以很明显的看出来,mysqlpump 的“并行导出”实际上只是基于表级别的并行导出,当存在单个大表的时候,导出的时间会被严重的影响,存在短板效应。
额外的疑问:如果default-parallelism和single-transaction有冲突的话,那么并行导出的时候是不是无法确认数据一致性?
实践出真实,打开 general_log 看一下导出时的操作:
|
2021-05-12t11:54:09.033215z 75 connect root@172.100.10.10 on using ssl/tls 2021-05-12t11:54:09.075347z 75 query flush tables with read lock //开始锁表 2021-05-12t11:54:09.103132z 75 query show warnings 2021-05-12t11:54:09.106382z 75 query set session transaction isolation level repeatable read 2021-05-12t11:54:09.106553z 75 query show warnings 2021-05-12t11:54:09.106640z 75 query start transaction with consistent snapshot 2021-05-12t11:54:09.108115z 75 query show warnings 2021-05-12t11:54:09.127277z 76 connect root@172.100.10.10 on using ssl/tls 2021-05-12t11:54:09.127452z 76 query set session transaction isolation level repeatable read 2021-05-12t11:54:09.127590z 76 query show warnings 2021-05-12t11:54:09.127680z 76 query start transaction with consistent snapshot 2021-05-12t11:54:09.127790z 76 query show warnings ...... 2021-05-12t11:54:10.018813z 90 connect root@172.100.10.10 on using ssl/tls 2021-05-12t11:54:10.018944z 90 query set session transaction isolation level repeatable read 2021-05-12t11:54:10.019047z 90 query show warnings 2021-05-12t11:54:10.019150z 90 query start transaction with consistent snapshot 2021-05-12t11:54:10.019226z 90 query show warnings 2021-05-12t11:54:10.025833z 91 connect root@172.100.10.10 on using ssl/tls 2021-05-12t11:54:10.025934z 91 query set session transaction isolation level repeatable read 2021-05-12t11:54:10.026048z 91 query show warnings 2021-05-12t11:54:10.026141z 91 query start transaction with consistent snapshot 2021-05-12t11:54:10.026219z 91 query show warnings 2021-05-12t11:54:10.026293z 75 query unlock tables //结束锁表 2021-05-12t11:54:10.026406z 75 query show warnings |
可以看到并行导出之前,有一个线程加上了全局读锁,然后等所有的并发线程打开事务之后才解锁了表,因此并行导出的时候也是数据一致的。
优缺点
-
优点:
- 并行备份数据库和数据库中的对象,比 mysqldump 更高效。
- 更好的控制数据库和数据库对象(表,存储过程,用户帐户)的备份。
- 备份进度可视化。
-
缺点:
- 只能并行到表级别,如果有一个表数据量特别大那么会存在非常严重的短板效应。
- 导出的数据保存在一个文件中,导入仍旧是单线程,效率较低。
- 无法获取当前备份对应的binlog位置。
总结一下
尽管 mysqlpump 还有非常多的不足,但是相比较于原始的 mysqldump 已经有了非常大的进步,从这个工具的发布也可以看出来 oracle 终于开始重视 mysql 的生态工具了,期待官方提供更多的更优秀的生态工具。
以上就是mysql官方导出工具mysqlpump的使用的详细内容,更多关于mysqlpump的使用的资料请关注开心学习网其它相关文章!
- mysql快速备份数据(如何使用Maxwell实时同步mysql数据)
- mysql插入数据错误代码(教你解决往mysql数据库中存入汉字报错的方法)
- mysql批量生成uuid(一种简单的ID生成策略: Mysql表生成全局唯一ID的实现)
- 查看mysql执行计划关键字(带你学习MySQL执行计划)
- 宝塔mysql怎么设置优化(宝塔面板mysql内存占用高如何优化)
- mysql查询count很慢(MySQL COUNT函数的使用与优化)
- 查询按照部门分组的mysql语句(Mysql根据某层部门ID查询所有下级多层子部门的示例)
- mysql的7种索引(浅入浅出 MySQL 索引)
- mysql安装详解(MySQL Router的安装部署)
- mysql编码设置
- centos7离线安装mysql5.7(CentOS7.5 安装MySql的教程)
- mysql 索引表空间(MySQL如何构建数据表索引)
- mysql游标的使用(MySQL 游标的作用与使用相关)
- 如何查看mysql慢查询日志(MySQL慢查询如何定位详解)
- mysql索引的弊端(MySQL 全文索引的原理与缺陷)
- mysql视图管理方法(MySQL 视图View原理解析)
- 盘点那些年让人称奇的年终奖 最后一个赢辣条毫无悬念(盘点那些年让人称奇的年终奖)
- 你还没有升职吗 他竟因为几套激励理论,升职了(你还没有升职吗)
- 某知名企业绩效管理体系及薪酬分配体系操作手册(某知名企业绩效管理体系及薪酬分配体系操作手册)
- 职场人改不掉这4个习惯,只会越混越穷,一辈子也翻不了身(职场人改不掉这4个习惯)
- 华为 联想等46家公司笔试面试题,涉及各行各业,建议收藏(联想等46家公司笔试面试题)
- ()
热门推荐
- mysql修改表结构的关键字(查看修改MySQL表结构命令)
- docker进入mysql查看路径(Docker 环境运行 Mysql 和开启 Binlog 配置主从同步的设置方法)
- pythontkinter详解(python3.6使用tkinter实现弹跳小球游戏)
- php技术优点和缺点(php的优点总结 php有哪些优点)
- sqlserver备份整表数据的语句(SqlServer批量备份多个数据库且删除3天前的备份)
- css标签及属性的语法规则(详解CSS 伪元素及Content 属性)
- 虚拟主机干嘛用的(虚拟主机购买后怎么操作?)
- js限制用户(如何用JS追踪用户)
- vue自定义组件修饰符(Vue自定义组件使用事件修饰符的踩坑记录)
- vmware esxi 网络配置(探索VMware ESXI CLI常用命令)