用户指南—数据导入和导出—使用Batch Tool工具导入导出数据

本文涉及的产品
应用型负载均衡 ALB,每月750个小时 15LCU
网络型负载均衡 NLB,每月750个小时 15LCU
传统型负载均衡 CLB,每月750个小时 15LCU
简介: 本文介绍了通过Batch Tool工具导入导出数据的方法。

工具介绍

Batch Tool工具是PolarDB-X团队开发的专为PolarDB-X数据库提供数据导入导出服务的工具。

Batch Tool工具采用JAVA语句实现,核心是生产者消费者模型,支持多线程操作,提供批量导出、批量导入、批量删除、批量更新等功能。数据以csv文件格式传输,方便用户进行数据交互。

Batch Tool工具的命令用法和参数如下:


usage: BatchTool [-?] [-batchsize ] [-con ] [-cs
           ] -D  [-dir ] [-f ] [-F
           ] [-func] -h  [-header] [-i] [-in] [-L ]
           [-lastSep] [-lb] [-local] [-maxConn ] [-minConn ]
           [-noesc] [-np] [-O ] -o  [-OC            column>] -p  [-P ] [-para] [-pre ] [-pro
           ] [-quote ] [-readsize ]
           [-rfonly] [-ringsize ] -s  [-t 
] -?,--help Help message. -batchsize,--batchSize Batch size of emitted tuples. -con,--consumer Configure number of consumer threads. -cs,--charset Define charset of files. -D,--database Database to use. -dir,--dir Directory path including files to import. -f,--from Source file(s), separated by ; . -F,--filenum Fixed number of exported files. -func,--sqlfunc Use sql function to update. -h,--host Connect to host. -header,--header Whether the header line is column names. -H,--historyFile history file name for resuming from breakpoint -i,--ignoreandresume Flag of insert ignore & resume from breakpoint -in,--wherein Using where ... in (...) -L,--line Max line limit of exported files. -lastSep,--withLastSep Whether line ends with separator. -lb,--loadbalance If using load balance. -local,--localmerge o local merge sort. -maxConn,--maxConnection Max connection number limit. -minConn,--minConnection Mim connection number limit. -noesc,--noescape Don't escape values. -np,--noparttion No use of parttion. -O,--orderby asc or desc. -o,--operation Batch operation type: export / import / delete / update. -OC,--orderCol col1;col2;col3. -p,--password Password to use when connecting to server. -P,--port Port number to use for connection. -para,--paraMerge Using parallel merge when doing order by export. -pre,--prefix Export file name prefix. -pro,--producer Configure number of producer threads. -quote,--quoteMode The mode of how field values are enclosed by double-quotes when exporting table. Default value is auto. -readsize,--readSize Read block size in MB. -rfonly,--rfonly Only read and process file, no sql execution. -ringsize,--ringBufferSize Ring buffer size. -s,--sep Separator between fields (delimiter). -t,--table -tps,--tpsLimit Tps limit -u,--user User for login. -w,--where Where condition: col1>99 AND col2<100 ...

参数说明

常用参数说明如下:

  • -o:批处理操作,包括export、import、delete、update四个选项。
  • -t:指定目标表名,只能为单个表。
  • -s:指定分隔符,可以为字符或字符串。
  • -f:指定源文件,多个文件名之间使用分号“;”分隔。
  • -OC:指定导出时排序使用的列名,多个列之间使用分号“;”分隔。
  • -cs:指定文本文件的字符集,默认为utf-8。
  • -lastSep:文件每行是否以分隔符结尾。
  • -quote:指定导出或导入时引号包围模式,包括以下三个可选值:
    • auto:默认模式,将根据字段值是否包含特殊字符(如分隔符、换行符等)来添加双引号;
    • force:强制每个字段值都添加双引号;
    • none:强制不添加双引号(适用于已知表字段类型都是数值型、或字符串型字段中不包含特殊字符的情况)。
  • -header:首行是否为字段名。
  • -i:是否开启insert ignore与断点续传。
  • -pre:指定导出文件名的前缀。
  • -F:指定导出文件数量。

工具获取

Batch Tool工具的jar包,单击下载:Batch_tool工具

使用示例

以编译生成的batch-tool.jar为例,查看参数说明:


java -jar batch-tool.jar -?
  • 批量导出数据
## 1.默认导出(文件数等于表的分片数)

java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o export -t table_name -s ,
## 2.导出文件数=3 (-F:指定文件数)
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o export -t table_name -s , -F 3
## 3.指定单个文件最大行数=10000 (-L:指定单文件行数)
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o export -t table_name -s , -L 10000
## 4.带where条件 若条件带有空格,需要使用引号 (-w:where条件语句)
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o export -t table_name -s , -w "id < 150 and id > 120"
  • 批量导入数据(需手动创建目标表,Batch Tool只包含数据传输)
## 1.多个文件用分号 (;) 分隔
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o import -t table_name -s , -f "table_name_0;table_name_1;table_name_2;table_name_3"
## 2.默认根据拆分键进行sharding插入, 如不采用,打开-np开关即可
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o import -t table_name -s , -f "file0;file2" -np
## 3.指定生产者、消费者线程(-pro:生产者线程,读取文件线程; -con:消费者线程,导入数据线程)
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o import -t table_name -s , -f "table_name_0;table_name_1" -np -pro 16 -con 16
## 4.打开insert ignore和断点续传
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o import -t table_name -s , -f "table_name_0;table_name_1" -i
  • 批量删除数据(删除数据库中包含文件中的数据,原理:构建DELETE语句,根据表结构填充文件中的数据)
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o delete -t table_name -s , -f "file0"
  • 批量更新数据(更新数据库中包含文件中的数据,原理:构建UPDTATE语句,根据表结构填充文件中的数据)
java -jar batch-tool.jar -h 127.0.0.1 -u testUser -p testPasswd -P 3306 -D db_name -o update -t table_name -s ,
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
相关文章
|
缓存 安全 关系型数据库
PolarDB 阿里云国产化数据库:linux系统下的详细安装步骤手册
PolarDB 阿里云国产化数据库:linux系统下的详细安装步骤手册
4980 0
PolarDB 阿里云国产化数据库:linux系统下的详细安装步骤手册
|
8月前
|
小程序
如何提升审核通过率?|阿里云短信服务
提升短信审核率的 tips 都在这里了哦!
557 15
|
存储 关系型数据库 MySQL
数据管理的艺术:PolarDB开源版详评与实战部署策略(一)
PolarDB-X是阿里巴巴自研的高性能云原生分布式数据库,基于共享存储的Shared-nothing架构,支持MySQL生态,具备金融级高可用、分布式水平扩展、HTAP混合负载等能力。它通过CN(计算节点)和DN(存储节点)实现计算与存储分离,保证数据强一致性,并支持全局二级索引和多主多写。PolarDB-X开源版提供更高程度的定制化和控制权,适合追求技术自主性和成本优化的开发者。部署方式包括RPM包、PXD工具和Kubernetes,其中PXD工具提供了一键部署的便利性。
236508 22
|
12月前
|
人工智能 监控 Shell
常用的 55 个 Linux Shell 脚本(包括基础案例、文件操作、实用工具、图形化、sed、gawk)
这篇文章提供了55个常用的Linux Shell脚本实例,涵盖基础案例、文件操作、实用工具、图形化界面及sed、gawk的使用。
1809 2
|
关系型数据库 MySQL Docker
PolarDB-X安装部署初体验
本文档介绍了体验阿里云PolarDB-X分布式数据库的安装和使用过程。首先提到PolarDB-X在稳定性及性能上的优势,然后详细描述了在CentOS 7环境下遇到的Python版本不兼容和Docker容器iptables配置问题的解决方法。通过创建Python 3.8的虚拟环境解决PyYAML依赖问题,接着在解决Docker容器内部网络问题后,成功安装并启动PolarDB-X。文中强调PolarDB-X完全兼容MySQL,适合熟悉MySQL的用户,并分享了安装历史记录以供参考。
437 7
|
SQL Kubernetes 关系型数据库
实践教程之快速安装部署PolarDB-X
PolarDB-X 为了方便用户体验,提供了免费的实验环境,您可以在实验环境里体验 PolarDB-X 的安装部署和各种内核特性。除了免费的实验,PolarDB-X 也提供免费的视频课程,手把手教你玩转 PolarDB-X 分布式数据库。
3250 0
实践教程之快速安装部署PolarDB-X
|
XML 运维 监控
PowerShell实战:Get-Content命令使用详解
【2月更文挑战第12篇】 Get-Content 主要作用是获取路径指定位置的项(文本类文件)的内容,例如文件中的文本或函数的内容。 对于文件,内容一次读取一行,并返回对象的集合,每个对象表示一行内容。
|
JSON C语言 数据格式
使用cJSON库实现JSON与C结构体的互转
在实际应用中,我们经常需要将JSON格式的数据与C语言中的结构体进行相互转换。cJSON是一个非常便捷的C语言JSON解析库,它可以帮助我们在C语言中轻松地处理JSON数据。本文将介绍如何使用cJSON库来实现JSON数据与C结构体的互转。
1075 2