当前位置: 首页 > news >正文

IoTDB 入门教程 基础篇⑪——Data导入导出工具

文章目录

  • 一、前文
  • 二、导出
    • 2.1 准备导出服务器
    • 2.2 导出命令
    • 2.3 执行命令
    • 2.4 sql文件
  • 三、导入
    • 3.1 准备导入服务器
    • 3.2 上传sql文件
    • 3.3 导入命令
    • 3.4 执行命令
  • 五、参考

一、前文

IoTDB入门教程——导读

如果是使用开源版本IoTDB,那么有如下三种数据同步和备份的方法,可供选择。

  • IoTDB 入门教程 基础篇⑨——TsFile导入导出工具
  • IoTDB 入门教程 基础篇⑩——CSV导入导出工具
  • IoTDB 入门教程 基础篇⑪——Data导入导出工具

如果是使用企业版本IoTDB(TimechoDB),那么一种数据同步的方法就够了,简单方便更好用。

  • IoTDB 入门教程 企业篇③——数据同步和增量备份
  • 数据库备份与迁移是数据库运维中的核心任务,其重要性不言而喻。
  • 确保备份过程既简单快捷又稳定可靠,对于保障数据安全与业务连续性至关重要。
  • 注意:IoTDB V1.3.2及之后版本使用tools/export-data、tools/import-data
  • 注意:IoTDB V1.3.1及之前版本使用tools/export-csv、tools/import-csv

tools/import-data支持两种数据格式

  • CSV:纯文本格式,存储格式化数据,需按照下文指定 CSV 格式进行构造
  • SQL:包含自定义 SQL 语句的文件

二、导出

2.1 准备导出服务器

  • 登录数据库
[root@iZgw0bdpdtyqxyz77dha9nZ apache-iotdb-1.3.2-all-bin]# bash sbin/start-cli.sh 
---------------------
Starting IoTDB Cli
---------------------_____       _________  ______   ______    
|_   _|     |  _   _  ||_   _ `.|_   _ \   | |   .--.|_/ | | \_|  | | `. \ | |_) |  | | / .'`\ \  | |      | |  | | |  __'.  _| |_| \__. | _| |_    _| |_.' /_| |__) | 
|_____|'.__.' |_____|  |______.'|_______/  version 1.3.2 (Build: aa0ff4a)Successfully login at 127.0.0.1:6667
  • 创建数据库
IoTDB> CREATE DATABASE root.test.test
Msg: The statement is executed successfully.
IoTDB> show databases
+--------------+----+-----------------------+---------------------+---------------------+
|      Database| TTL|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|
+--------------+----+-----------------------+---------------------+---------------------+
|root.test.test|null|                      1|                    1|            604800000|
+--------------+----+-----------------------+---------------------+---------------------+
Total line number = 1
It costs 0.006s
  • 写入数据库
IoTDB> INSERT INTO root.test.test(status) values(1)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(2)
Msg: The statement is executed successfully.
IoTDB> INSERT INTO root.test.test(status) values(3)
Msg: The statement is executed successfully.
  • 查询数据库
IoTDB> select * from root.test.test order by time desc
+-----------------------------+---------------------+
|                         Time|root.test.test.status|
+-----------------------------+---------------------+
|2024-08-04T09:29:08.893+08:00|                  3.0|
|2024-08-04T09:29:06.757+08:00|                  2.0|
|2024-08-04T09:29:04.169+08:00|                  1.0|
+-----------------------------+---------------------+
Total line number = 3
It costs 0.141s

2.2 导出命令

bash tools/export-data.sh  -h <ip> -p <port> -u <username> -pw <password> -td <directory> [-tf <time-format> -datatype <true/false> -q <query command> -s <sql file>]
usage: ExportData -h <host> -p <port> -u <username> [-pw <password>] -td <targetDirectory>[-f <targetFile>] [-s <sqlfile>] [-tf <timeformat>] [-tz <timeZone>] [-datatype<datatype>] [-q <queryCommand>] [-type <exportType>] [-aligned <export aligned insertsql>] [-linesPerFile <Lines Per File>] [-help] [-t <arg>]-h,--host <host>                       Host Name (required)-p,--port <port>                       Port (required)-u,--username <username>               Username (required)-pw,--password <password>              Password (required)-td <targetDirectory>                  Target File Directory (required)-f <targetFile>                        Export file name (optional)-s <sqlfile>                           SQL File Path (optional)-tf <timeformat>                       Output time Format in csv file. You can choose 1)timestamp, number, long 2) ISO8601, default 3)user-defined pattern like yyyy-MM-dd HH:mm:ss,default ISO8601.OutPut timestamp in sql file, No matter what timeformat is set(optional)-tz <timeZone>                         Time Zone eg. +08:00 or -01:00 (optional)-datatype <datatype>                   Will the data type of timeseries be printed in thehead line of the CSV file?You can choose true) or false) . (optional)-q <queryCommand>                      The query command that you want to execute.(optional)-type <exportType>                     Export file type ?You can choose csv) or sql) . (optional)-aligned <export aligned insert sql>   Whether export to sql of aligned (only sql optional)-linesPerFile <Lines Per File>         Lines per dump file.-help,--help                           Display help information-t,--timeout <arg>                     Timeout for session query

2.3 执行命令

[root@iZgw0bdpdtyqxyz77dha9nZ apache-iotdb-1.3.2-all-bin]# bash tools/export-data.sh -h '127.0.0.1' -p 6667 -u root -pw root -td ./ -q 'select * from root.test.test order by time desc' -type sql
------------------------------------------
Starting IoTDB Client Export Script
------------------------------------------
Export completely!

2.4 sql文件

  • dump0_0.sql就是本次导出的sql文件。

在这里插入图片描述
在这里插入图片描述

三、导入

3.1 准备导入服务器

  • 登录数据库
[root@iZgw0bdpdtyqxyz77dha9nZ apache-iotdb-1.3.2-all-bin]# bash sbin/start-cli.sh 
---------------------
Starting IoTDB Cli
---------------------_____       _________  ______   ______    
|_   _|     |  _   _  ||_   _ `.|_   _ \   | |   .--.|_/ | | \_|  | | `. \ | |_) |  | | / .'`\ \  | |      | |  | | |  __'.  _| |_| \__. | _| |_    _| |_.' /_| |__) | 
|_____|'.__.' |_____|  |______.'|_______/  version 1.3.2 (Build: aa0ff4a)Successfully login at 127.0.0.1:6667
  • 删除数据
IoTDB> DELETE FROM root.test.test.status where time < 40000000000000
Msg: The statement is executed successfully.
  • 查询数据库,没有数据
IoTDB> select status from root.test.test
+----+
|Time|
+----+
+----+
Empty set.
It costs 0.184s

3.2 上传sql文件

将在2.4小节获得的dump0_0.sql上传到导入服务器中

3.3 导入命令

bash tools/import-data.sh -h <ip> -p <port> -u <username> -pw <password> -s <xxx.csv/sql> [-fd <./failedDirectory> -aligned <true/false> -batch <int> -tp <ms/ns/us> -typeInfer <boolean=text,float=double...> -lpf <int>]
usage: ImportData -h <host> -p <port> -u <username> [-pw <password>] -f <file or folder>[-fd <failed file directory>] [-aligned <use the aligned interface>] [-help] [-tz<timeZone>] [-batch <batch point size>] [-tp <timestamp precision (ms/us/ns)>][-typeInfer <type infer>] [-linesPerFailedFile <Lines Per FailedFile>]-h,--host <host>                             Host Name (required)-p,--port <port>                             Port (required)-u,--username <username>                     Username (required)-pw,--password <password>                    Password (required)-f <file or folder>                          If input a file path, load a csv file,otherwise load all csv file under thisdirectory (required)-fd <failed file directory>                  Specifying a directory to save failed file,default YOUR_CSV_FILE_PATH (optional)-aligned <use the aligned interface>         Whether to use the interface of aligned(onlycsv optional)-help,--help                                 Display help information-tz <timeZone>                               Time Zone eg. +08:00 or -01:00 (optional)-batch <batch point size>                    100000 (optional)-tp <timestamp precision (ms/us/ns)>         Timestamp precision (ms/us/ns)-typeInfer <type infer>                      Define type info byoption:"boolean=text,int=long, ...-linesPerFailedFile <Lines Per FailedFile>   Lines per failed file

3.4 执行命令

  • 导入sql文件
[root@iZgw0bdpdtyqxyz77dha9nZ apache-iotdb-1.3.2-all-bin]# bash tools/import-data.sh -f ./dump0_0.sql -h 127.0.0.1 -p 6667 -u root -pw root
------------------------------------------
Starting IoTDB Client Import Script
------------------------------------------
dump0_0.sql Import completely!
  • 登录数据库
[root@iZgw0bdpdtyqxyz77dha9nZ apache-iotdb-1.3.2-all-bin]# bash sbin/start-cli.sh 
---------------------
Starting IoTDB Cli
---------------------_____       _________  ______   ______    
|_   _|     |  _   _  ||_   _ `.|_   _ \   | |   .--.|_/ | | \_|  | | `. \ | |_) |  | | / .'`\ \  | |      | |  | | |  __'.  _| |_| \__. | _| |_    _| |_.' /_| |__) | 
|_____|'.__.' |_____|  |______.'|_______/  version 1.3.2 (Build: aa0ff4a)Successfully login at 127.0.0.1:6667
  • 查询数据是否成功导入
IoTDB> select * from root.test.test order by time desc
+-----------------------------+---------------------+
|                         Time|root.test.test.status|
+-----------------------------+---------------------+
|2024-08-04T09:29:08.893+08:00|                  3.0|
|2024-08-04T09:29:06.757+08:00|                  2.0|
|2024-08-04T09:29:04.169+08:00|                  1.0|
+-----------------------------+---------------------+
Total line number = 3
It costs 0.073s

五、参考

数据导入导出脚本 | IoTDB Website

觉得好,就一键三连呗(点赞+收藏+关注)

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Vue3+TS+element plus实现一个简单列表页面
  • 《Milvus Cloud向量数据库指南》——Milvus Cloud——Ivy.ai业务创新的坚实基石
  • 两个月后,我又开发了一款图片制作工具
  • 【Golang 面试 - 进阶题】每日 3 题(十三)
  • 高通8255 Android Virtio Virtio-IIC 配置方法
  • WPF学习(2)-UniformGrid控件(均分布局)+StackPanel控件(栈式布局)
  • 优秀的行为验证码的应用场景与行业案例
  • rancher v2.4.17安装部署并授权永久使用
  • 动手学深度学习V2每日笔记(经典卷积神经网络LeNet)
  • 0205其它新型电力电子器件
  • C语言 | Leetcode C语言题解之第324题摆动排序II
  • word加密文档忘记密码要如何打开
  • Linux的目录文件函数接口,链接文件函数接口,获得文件详细信息
  • 【嵌入式】RTOS和Linux的区别
  • ios如何动态添加控件及动画
  • Angular Elements 及其运作原理
  • create-react-app项目添加less配置
  • CSS实用技巧
  • JavaScript学习总结——原型
  • Linux gpio口使用方法
  • miaov-React 最佳入门
  • Vue2.0 实现互斥
  • windows下mongoDB的环境配置
  • 从tcpdump抓包看TCP/IP协议
  • 读懂package.json -- 依赖管理
  • 基于web的全景—— Pannellum小试
  • 名企6年Java程序员的工作总结,写给在迷茫中的你!
  • 怎样选择前端框架
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • ​​​【收录 Hello 算法】10.4 哈希优化策略
  • ​Java基础复习笔记 第16章:网络编程
  • #define 用法
  • (+4)2.2UML建模图
  • (Arcgis)Python编程批量将HDF5文件转换为TIFF格式并应用地理转换和投影信息
  • (Matlab)基于蝙蝠算法实现电力系统经济调度
  • (分类)KNN算法- 参数调优
  • (回溯) LeetCode 40. 组合总和II
  • (三)Honghu Cloud云架构一定时调度平台
  • (贪心) LeetCode 45. 跳跃游戏 II
  • (已解决)报错:Could not load the Qt platform plugin “xcb“
  • (原創) 人會胖會瘦,都是自我要求的結果 (日記)
  • (转)linux自定义开机启动服务和chkconfig使用方法
  • (转)Windows2003安全设置/维护
  • (转)用.Net的File控件上传文件的解决方案
  • .NET gRPC 和RESTful简单对比
  • .net oracle 连接超时_Mysql连接数据库异常汇总【必收藏】
  • .NET 给NuGet包添加Readme
  • .net 开发怎么实现前后端分离_前后端分离:分离式开发和一体式发布
  • .NET 药厂业务系统 CPU爆高分析
  • .Net 中Partitioner static与dynamic的性能对比
  • .NET 中创建支持集合初始化器的类型
  • .NET开发不可不知、不可不用的辅助类(一)
  • /usr/bin/perl:bad interpreter:No such file or directory 的解决办法
  • @TableId注解详细介绍 mybaits 实体类主键注解
  • [APIO2015]巴厘岛的雕塑