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

简介: 本文介绍了通过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应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
相关文章
|
5月前
|
运维 监控 安全
阿里云国际版(云老大):云安全中心文件完整性监控配置步骤,应对服务器文件异常篡改
配置阿里云云安全中心文件完整性监控之前,有必要先厘清这套机制到底在监控什么、能解决哪些实际问题。它的价值往往被低估,直到服务器上的关键文件被悄无声息地篡改,业务中断或数据泄露数天后才发现,复盘时只能依赖零散日志,溯源极其困难。
阿里云国际版(云老大):云安全中心文件完整性监控配置步骤,应对服务器文件异常篡改
|
数据采集 供应链 API
实战指南:通过1688开放平台API获取商品详情数据(附Python代码及避坑指南)
1688作为国内最大的B2B供应链平台,其API为企业提供合法合规的JSON数据源,直接获取批发价、SKU库存等核心数据。相比爬虫方案,官方API避免了反爬严格、数据缺失和法律风险等问题。企业接入1688商品API需完成资质认证、创建应用、签名机制解析及调用接口四步。应用场景包括智能采购系统、供应商评估模型和跨境选品分析。提供高频问题解决方案及安全合规实践,确保数据安全与合法使用。立即访问1688开放平台,解锁B2B数据宝藏!
|
Web App开发 移动开发 JavaScript
|
9天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17555 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
3天前
|
人工智能 安全 网络安全

热门文章

最新文章