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

简介: 本文介绍了通过Batch Tool工具导入导出数据的方法。

工具介绍

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

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

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


usage: BatchTool [-?] [-batchsize <arg>] [-con <consumer count>] [-cs
           <charset>] -D <database> [-dir <directory>] [-f <from>] [-F
           <filenum>] [-func] -h <host> [-header] [-i] [-in] [-L <line>]
           [-lastSep] [-lb] [-local] [-maxConn <arg>] [-minConn <arg>]
           [-noesc] [-np] [-O <order by type>] -o <operation> [-OC <ordered
           column>] -p <password> [-P <port>] [-para] [-pre <prefix>] [-pro
           <producer count>] [-quote <auto/force/none>] [-readsize <arg>]
           [-rfonly] [-ringsize <arg>] -s <sep> [-t <table>] -u <user> [-w
           <where>]
     -?,--help                              Help message.
     -batchsize,--batchSize <arg>           Batch size of emitted tuples.
     -con,--consumer <consumer count>       Configure number of consumer
                                            threads.
     -cs,--charset <charset>                Define charset of files.
     -D,--database <database>               Database to use.
     -dir,--dir <directory>                 Directory path including files to
                                            import.
     -f,--from <from>                       Source file(s), separated by ; .
     -F,--filenum <filenum>                 Fixed number of exported files.
     -func,--sqlfunc                        Use sql function to update.
     -h,--host <host>                       Connect to host.
     -header,--header                       Whether the header line is column
                                            names.
     -H,--historyFile <filename>            history file name for resuming from breakpoint
     -i,--ignoreandresume                   Flag of insert ignore & resume from breakpoint
     -in,--wherein                          Using where ... in (...)
     -L,--line <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 <arg>         Max connection number limit.
     -minConn,--minConnection <arg>         Mim connection number limit.
     -noesc,--noescape                      Don't escape values.
     -np,--noparttion                       No use of parttion.
     -O,--orderby <order by type>           asc or desc.
     -o,--operation <operation>             Batch operation type: export /
                                            import / delete / update.
     -OC,--orderCol <ordered column>        col1;col2;col3.
     -p,--password <password>               Password to use when connecting to
                                            server.
     -P,--port <port>                       Port number to use for connection.
     -para,--paraMerge                      Using parallel merge when doing
                                            order by export.
     -pre,--prefix <prefix>                 Export file name prefix.
     -pro,--producer <producer count>       Configure number of producer
                                            threads.
     -quote,--quoteMode <auto/force/none>   The mode of how field values are
                                            enclosed by double-quotes when
                                            exporting table. Default value is
                                            auto.
     -readsize,--readSize <arg>             Read block size in MB.
     -rfonly,--rfonly                       Only read and process file, no sql
                                            execution.
     -ringsize,--ringBufferSize <arg>       Ring buffer size.
     -s,--sep <sep>                         Separator between fields
                                            (delimiter).
     -t,--table <table>                     Target table.
     -tps,--tpsLimit <arg>                  Tps limit
     -u,--user <user>                       User for login.
     -w,--where <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应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
相关文章
|
9天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17393 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
3天前
|
人工智能 安全 网络安全
|
6天前
|
云安全 数据采集 人工智能
|
8天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1351 5
|
14天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2419 8
|
19天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
3906 22
|
20天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是DeepSeek AI开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、跑命令、处理表格、联网搜索等操作。免费开源,兼容Windows/macOS/Linux,提供桌面端与网页端,可灵活安装插件扩展能力。

热门文章

最新文章