时序数据库TDengine安装及c#连接读写数据

news2024/9/20 16:42:39

物联网数据采集,需写入大量数据,这时就用到时序数据库来存储和快速读取

我个人使用感觉国产的开源项目TDengine,比InfluxDB操作方便很多,容易上手,支持使用SqlSugar进行数据操作,跟操作mysql数据库一样的体验

跟mysql最有特别之处,就是TDengine有个超级表=表结构模板 的概念,可以基于这个超级表的结构,建N个数量的子表,查询的时候,可以查单个子表,也可以查超级表所有子表的数据集合

超级表概念如:

建超级表A

基于超级表A的结构 建子表 : A1、A2、A3、N

然后查询的时候,可以单查A1表数据,也可以通过超级表A查所有A1、A2...集合的数据出来

用在传感器数据采集日志,一个设备一个表,最适合不过

TDengine官网技术文档 :https://docs.taosdata.com/connector/csharp/

一、window下安装TDengine

https://docs.taosdata.com/releases/tdengine/

找到同时有server和client 的版本

TDengine-server-xxx-Windows  数据库主安装文件
TDengine-client-xxx-Windows  数据库连接工具

二、服务端安装:

1、双击TDengine-server-3.0.7.1-Windows-x64.exe 安装,一直回车即可

2、配置数据库变量

打开C:\TDengine\cfg下的taos.cfg

########################################################
#                                                      #
#                  TDengine Configuration              #
#   Any questions, please email support@taosdata.com   #
#                                                      #
########################################################

# first fully qualified domain name (FQDN) for TDengine system
# taosd启动时,主动连接的集群中第一个dnode的end point, 默认值为localhost:6030。
firstEp               vm1:6030

# second fully qualified domain name (FQDN) for TDengine system, for cluster only
# taosd启动时,如果first连接不上,尝试连接集群中第二个dnode的end point, 默认值为空。
secondEp              vm2:6030

# local fully qualified domain name (FQDN)
# 数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。
fqdn                  vm1

# first port number for the connection (12 continuous UDP/TCP port number are used) 
# taosd启动后,对外服务的端口号,默认值为6030。
serverPort            6030

# log file's directory
# 日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos。
logDir                /home/radmin/data/tdengine/log

# data file's directory
# 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。
dataDir               /home/radmin/data/tdengine/data

# the arbitrator's fully qualified domain name (FQDN) for TDengine system, for cluster only   
# 系统中裁决器的end point, 缺省值为空。
# arbitrator            arbitrator_hostname:6042     

# number of threads per CPU core
# numOfThreadsPerCore   1.0

# number of management nodes in the system
# 系统中管理节点个数。默认值:3。
# numOfMnodes           3

# enable/disable backuping vnode directory when removing dnode
# vnodeBak              1

# enable/disable load balancing
# 是否启动负载均衡。0:否,1:是。默认值:1。
# balance               1

# role for dnode. 0 - any, 1 - mnode, 2 - dnode
# dnode的可选角色。0-any; 既可作为mnode,也可分配vnode;1-mgmt;只能作为mnode,不能分配vnode;2-dnode;不能作为mnode,只能分配vnode
# role                  0

# max timer control blocks
# maxTmrCtrl            512

# time interval of system monitor, seconds 
# monitorInterval       30

# number of seconds allowed for a dnode to be offline, for cluster only 
# dnode离线阈值,超过该时间将导致该dnode从集群中删除。单位为秒,默认值:86400*10(即10天)。
# offlineThreshold      8640000

# RPC re-try timer, millisecond
# rpcTimer              300

# RPC maximum time for ack, seconds. 
# rpcMaxTime            600

# time interval of dnode status reporting to mnode, seconds, for cluster only 
# statusInterval        1

# time interval of heart beat from shell to dnode, seconds
# shellActivityTimer    3

# time of keeping table meta data in cache, seconds
# tableMetaKeepTimer    7200

# minimum sliding window time, milli-second
# minSlidingTime        10

# minimum time window, milli-second
# minIntervalTime       10

# maximum delay before launching a stream compution, milli-second
# maxStreamCompDelay    20000

# maximum delay before launching a stream computation for the first time, milli-second
# maxFirstStreamCompDelay   10000

# retry delay when a stream computation fails, milli-second
# retryStreamCompDelay      10

# the delayed time for launching a stream computation, from 0.1(default, 10% of whole computing time window) to 0.9
# streamCompDelayRatio      0.1

# max number of vgroups per db, 0 means configured automatically
# 每个数据库中能够使用的最大vnode个数。
# maxVgroupsPerDb           0

# max number of tables per vnode
# 每个vnode中能够创建的最大表个数。默认值:1000000。
# maxTablesPerVnode         1000000

# step size of increasing table number in a vnode
# tableIncStepPerVnode      1000

# cache block size (Mbyte)
# cache                     16

# number of cache blocks per vnode
# blocks                    6

# number of days per DB file
# 一个数据文件存储数据的时间跨度,单位为天,默认值:10。
# days                  10

# number of days to keep DB file
# 数据库中数据保留的天数,单位为天,默认值:3650。
# keep                  3650

# minimum rows of records in file block
# 文件块中记录的最小条数,单位为条,默认值:100。
# minRows               100

# maximum rows of records in file block
# 文件块中记录的最大条数,单位为条,默认值:4096。
# maxRows               4096

# enable/disable compression
# 文件压缩标志位,0:关闭,1:一阶段压缩,2:两阶段压缩。默认值:2。
# comp                  2

# write ahead log (WAL) level, 0: no wal; 1: write wal, but no fysnc; 2: write wal, and call fsync
# WAL级别。1:写wal, 但不执行fsync; 2:写wal, 而且执行fsync。默认值:1。
# walLevel              1

# if walLevel is set to 2, the cycle of fsync being executed, if set to 0, fsync is called right away
# 当wal设置为2时,执行fsync的周期。设置为0,表示每次写入,立即执行fsync。单位为毫秒,默认值:3000。
# fsync                 3000

# number of replications, for cluster only 
# 副本个数,取值范围:1-3。单位为个,默认值:1
replica               3

# mqtt hostname  
# mqttHostName          test.mosquitto.org

# mqtt port  
# mqttPort              1883

# mqtt topic
# mqttTopic             /test

# the compressed rpc message, option:
#  -1 (no compression)
#   0 (all message compressed),
# > 0 (rpc message body which larger than this value will be compressed)
# compressMsgSize       -1

# max length of an SQL
# 单条SQL语句允许最长限制。默认值:65380字节。
maxSQLLength          1048576

# the maximum number of records allowed for super table time sorting
# maxNumOfOrderedRes    100000

# system time zone
# 默认值:从系统中动态获取当前的时区设置
# timezone              Asia/Shanghai (CST, +0800)

# system locale
# 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置
# locale                en_US.UTF-8

# default system charset
# 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置
# charset               UTF-8

# max number of connections allowed in dnode
# maxShellConns         5000

# max numerber of connections allowed in client 
# maxConnections        5000

# stop writing logs when the disk size of the log folder is less than this value
# minimalLogDirGB       0.1

# stop writing temporary files when the disk size of the log folder is less than this value
# minimalTmpDirGB       0.1

# stop writing data when the disk size of the log folder is less than this value
# minimalDataDirGB      0.1

# enbale/disable http service
# http                  1

# enable/disable muqq service
# mqtt                  0

# enable/disable system monitor 
# monitor               1

# enable/disable recording the SQL statements via restful interface
# httpEnableRecordSql   0

# number of threads used to process http requests
# httpMaxThreads        2

# maximum number of rows returned by the restful interface
# restfulRowLimit       10240

# The following parameter is used to limit the maximum number of lines in log files.
# max number of rows per log filters
# 单个日志文件允许的最大行数。默认值:10,000,000行。
# numOfLogLines         10000000

# time of keeping log files, days
# 日志文件的最长保存时间。大于0时,日志文件会被重命名为taosdlog.xxx,其中xxx为日志文件最后修改的时间戳,单位为秒。默认值:0天。
# logKeepDays           0

# enable/disable async log
# asyncLog              1

# The following parameters are used for debug purpose only.
# debugFlag 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR
# 131: output warning and error, 135: output debug, warning and error, 143 : output trace, debug, warning and error to log.
# 199: output debug, warning and error to both screen and file
# 207: output trace, debug, warning and error to both screen and file

# debug flag for all log type, take effect when non-zero value
# debugFlag             0

# debug flag for meta management messages
# mDebugFlag            135

# debug flag for dnode messages
# dDebugFlag            135

# debug flag for sync module
# sDebugFlag            135

# debug flag for WAL
# wDebugFlag            135

# debug flag for SDB
# sdbDebugFlag          135

# debug flag for RPC 
# rpcDebugFlag          131

# debug flag for TAOS TIMER
# tmrDebugFlag          131

# debug flag for TDengine client 
# cDebugFlag            131

# debug flag for JNI
# jniDebugflag          131

# debug flag for ODBC
# odbcDebugflag         131

# debug flag for storage
# uDebugflag            131

# debug flag for http server
# httpDebugFlag         131

# debug flag for mqtt
# mqttDebugFlag         131

# debug flag for monitor
# monitorDebugFlag      131

# debug flag for query
# qDebugflag            131

# debug flag for vnode
# vDebugflag            131

# debug flag for http server
# tsdbDebugFlag         131

# enable/disable recording the SQL in taos client
# tscEnableRecordSql    0

# generate core file when service crash
# enableCoreFile        1

# maximum display width of binary and nchar fields in the shell. The parts exceeding this limit will be hidden
# maxBinaryDisplayWidth 30

3、在E盘创建文件夹

创建TDengine文件夹,在TDengine文件夹下创建log文件夹和data文件夹

 4、启动数据库服务

进入C:\TDengine,双击taosd.exe,等待启动。

5、测试下

双击桌面的Taos Shell,输入 taos 运行

查看用户

taos> show users; 

 服务端安装完毕

6、开放服务器端口6030

三、客户端window为例

1、安装客户端安装包

TDengine-client-xxx-Windows  数据库连接工具

安装好后,打开目录C:\TDengine\cfg

修改配置文件taos.cfg

firstEp 值修改为服务端的IP和端口

3、测试连接 

打开taos.exe,看到这样为连接成功

创建用户

create user admin pass '123456';

查看用户

show users;

创建数据库

CREATE DATABASE   iot_devicedatacenter;

修改超级表标签
ALTER STABLE  stable_device_valuelog ADD TAG modelid INT;
ALTER STABLE  stable_device_valuelog RENAME TAG cid clientid;

修改子表标签
ALTER TABLE tb_device_valuelog_2 SET TAG modelid=0;

统计和
select sum(cast(dvalue as INT)) from tb_device_valuelog_2 where ts>="2023-12-06 00:00:00.000";

四、C#程序调用

 代码例子:

using TDengineDriver;
using SqlSugar;
using Newtonsoft.Json;

public void SqlSugarTest()
{


    var db = new SqlSugarClient(new ConnectionConfig()
    {
        DbType =SqlSugar.DbType.TDengine,
        ConnectionString = "Host=localhost(服务器IP);Port=6030;Username=root;Password=taosdata;Database=power",
        IsAutoCloseConnection = true
    });
    //建超级表
    db.Ado.ExecuteCommand("CREATE STABLE IF NOT EXISTS  stable_device_valuelog (ts TIMESTAMP, dkey NCHAR(20), dvalue NCHAR(20)) TAGS (did INT,cid INT)");
   //建数据表并写入数据
    db.Ado.ExecuteCommand(@" INSERT INTO tb_device_valuelog01 USING stable_device_valuelog TAGS(1, 2) VALUES(NOW,'status','no');");
    //读数据
    DataTable dt = db.Ado.GetDataTable("select * from tb_device_valuelog01 ");
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1304436.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Python简单网抑云数据采集 JS逆向

嗨喽,大家好呀~这里是爱看美女的茜茜呐 环境使用: Python 3.10 Pycharm 模块使用: requests -> pip install requests execjs -> pip install execjs 爬虫实现基本思路流程: 一. 数据来源分析: 明确需求: 明确采集的网站以及数据内容 网址: https://mu…

HCIA-H12-811题目解析(3)

1、【单选题】 以下关于路由器的描述,说法错误的是? 2、【单选题】某网络工程师在输入命令行时提示如下信息:Error:Unrecognized command foun at position.对于该提示信息说法正确的是? 3、【单选题】如下图所示的网络&#xf…

时间戳与QDateTime转换,以及QString转时间戳

1、主要有时间戳->QDateTime,QDateTime->QString 2、同时QString->QDateTime,QDateTime->时间戳 详情见代码&#xff1a; //QDateTime转时间戳qint64 time QDateTime::currentSecsSinceEpoch();double nowTime (double)time;qDebug()<<"nowTime1111…

小米耳机定制音效选项灰色无法开启使用_开启定制音效_音效模式设置_音效使用教程

使用环境&#xff1a;Redmi K50 Ultra &#xff0b;MIUI 14.0.11&#xff0b;定制音效选项是灰色的无法开启及音效模式无法选择 定制音效无法开启 音效模式无法选择&#xff08;需下载小米耳机APP才能设置&#xff09;&#xff0c;根据提示解决问题即可 解决方法&#xff1a;关…

IDEA使用小技巧

常用的基本设置 界面字体 File | Settings | Appearance & Behavior | Appearance 编辑区字体 File | Settings | Editor | Color Scheme | Color Scheme Font Use color scheme font instead of the default 控制台字体 File | Settings | Editor | Color Scheme | Conso…

UCOS-II/III移植及相关问题【2】

移植过程中的问题&#xff1a; 提示&#xff1a;基于正点原子移植文档操作&#xff1a; STM32F767移植UCOS-II object file renamed from ‘.o‘ to ‘_1.o 提示&#xff1a;网络海淘大致就是文件重复了 解决方案&#xff1a; 将出问题的相关文件夹中文件删除重新添加 移…

大数据Vue项目必备|Window下安装并使用nvm(含卸载node、卸载nvm、全局安装npm)

大数据Vue项目必备|Window下安装并使用nvm&#xff08;含卸载node、卸载nvm、全局安装npm&#xff09; 一、卸载旧版本 如果已经安装了node&#xff0c;那么需要先卸载node&#xff0c;如果没有安装那可以直接跳过这一步。 卸载&#xff1a;   打开控制面板 -> 打开程序和…

Git篇---第五篇

系列文章目录 文章目录 系列文章目录前言一、提交对象包含什么?二、如何在Git中创建存储库?三、怎样将 N 次提交压缩成一次提交?前言 前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站,这篇文章男女通用,看懂了就去分…

李飞飞携斯坦福联袂谷歌推出比肩Pika的视频生成模型W.A.L.T

英国数据保护监管机构敦促公司在使用人工智能&#xff08;AI&#xff09;时认真考虑人们的隐私权&#xff0c;否则不仅可能面临罚款&#xff0c;还可能失去公众对该技术的信任。信息专员约翰爱德华兹在周三的一次演讲中表示&#xff0c;公司在使用AI时必须在所有情况下保护客户…

网易有道强力开源中英双语语音克隆

项目地址&#xff08;基于PromptTTS&#xff09;&#xff1a; https://github.com/netease-youdao/EmotiVoice EmotiVoice Docker镜像 尝试EmotiVoice最简单的方法是运行docker镜像。你需要一台带有NVidia GPU的机器。先按照Linux和Windows WSL2平台的说明安装NVidia容器工具…

以企业架构为中心的SABOE数字化转型五环法

文章目录 01 传统企业数字化转型面临诸多挑战02 SABOE数字化转型五环法为企业转型破除迷雾 01 传统企业数字化转型面临诸多挑战 即将过去的2023年&#xff0c;chatGPT大模型、数据资产入表等事件的发生&#xff0c;标志着数字经济正在加速发展。数字经济是人类社会继农业经济、…

C++ Qt开发:LineEdit单行输入组件

Qt 是一个跨平台C图形界面开发库&#xff0c;利用Qt可以快速开发跨平台窗体应用程序&#xff0c;在Qt中我们可以通过拖拽的方式将不同组件放到指定的位置&#xff0c;实现图形化开发极大的方便了开发效率&#xff0c;本章将重点介绍LineEdit单行输入框组件的常用方法及灵活运用…

【面试总结】Java面试题目总结(一)

&#xff08;以下仅为个人见解&#xff0c;如果有误&#xff0c;欢迎大家批评并指出错误&#xff0c;谢谢大家&#xff09; 1.项目中的验证码功能是如何实现的&#xff1f; 第一步&#xff1a;在项目的pom.xml文件中导入 EasyCaptcha 的依赖&#xff1b; <dependency>…

【教程】app备案流程简单三部曲即可完成

APP备案流程包括以下步骤&#xff1a; 1. 开发者实名认证&#xff1a;在提交备案申请之前&#xff0c;开发者需要通过移动应用开发平台进行实名认证。这个步骤需要提供身份证号码、姓名、联系方式等信息&#xff0c;并上传相关证件照片或扫描件。 2. 应用信息登记&#xff1a…

Android 等待view 加载布局完成 (包括动态生成View)

前言 在实际开发中&#xff0c;有很多组件需要 根据数据&#xff0c;动态生成&#xff0c;或者 追加 / 减少 子view&#xff0c;由于View布局需要时间&#xff0c;此时想要获取父View的最新宽高值&#xff0c;要么手动测量&#xff0c;要么等待布局完成后再获取&#xff1b; …

QEMU源码全解析 —— virtio(1)

接前一篇文章&#xff1a; 本文内容参考&#xff1a; 《趣谈Linux操作系统》 —— 刘超&#xff0c;极客时间 《QEMU/KVM》源码解析与应用 —— 李强&#xff0c;机械工业出版社 特此致谢&#xff01; virtio简介 对于一台虚拟机而言&#xff0c;除了要虚拟化CPU和内存&…

【大模型】800万纯AI战士年末大集结,硬核干货与音乐美食12月28日准时开炫

文章目录 WAVE SUMMIT五载十届&#xff0c;AI开发者热血正当时酷炫前沿、星河共聚&#xff01;大模型技术生态发展正当时 回望2023年&#xff0c;大语言模型或许将是科技史上最浓墨重彩的一笔。从技术、产业到生态&#xff0c;大语言模型在突飞猛进中加速重构万物。随着理解、生…

【 TES720D】基于国内某厂商的FMQL20S400全国产化ARM核心模块

板卡概述 TES720D是一款基于国内某厂商FMQL20S400的全国产化核心模块。该核心模块将FMQL20S400&#xff08;兼容FMQL10S400&#xff09;的最小系统集成在了一个50*70mm的核心板上&#xff0c;可以作为一个核心模块&#xff0c;进行功能性扩展&#xff0c;特别是用在控制领域&a…

STM32CubeIDE 移植 RT-ThreadNano问题总结

问题汇总 用STM32CubeIDE新建工程时&#xff0c;用STM32CubeMX勾选了RTThread系统&#xff0c;但是生产的工程中没有MiddleWare。 原因&#xff1a;因为更换过workspace,更换完成后配置Firmware and software package时选择到了D:\STM32Cube。 解决&#xff1a;STM32CubeIDE系…

【自定义Source、Sink】Flink自定义Source、Sink对redis进行读写操作

使用ParameterTool读取配置文件 Flink读取参数的对象 Commons-cli&#xff1a; Apache提供的&#xff0c;需要引入依赖ParameterTool&#xff1a;Flink内置 ParameterTool 比 Commons-cli 使用上简便&#xff1b; ParameterTool能避免Jar包的依赖冲突 建议使用第二种 使用Par…