安装
https://www.taosdata.com/cn/getting-started/
$ tar -xvzf TDengine-server-2.3.0.0-beta-Linux-x64.tar.gz
$ cd TDengine-server-2.3.0.0
$ ./install.sh
默认信息
端口 6030
用户:root
密码:taosdata
$ taos
$ create database power KEEP 365; // 建库(保留365天)
$ USE power;
$ CREATE STABLE meters (ts timestamp, current float, voltage int) TAGS (location binary(64), groupdId int); // 创建超级表(电表:电流+电压,标签)
$ INSERT INTO d1001 USING meters TAGS (“Beijng.Chaoyang”, 2) VALUES (now, 10.2, 219); // 自动创建子表
解决客户端连接报错”Unable to resolve FQDN”
1. 查询TDengine所在Linux服务端的hostname
2.
对于Linux系统的客户端,在/etc/hosts文件添加如下的一条记录:192.168.1.131 chen
对于Windows系统的客户端,在C:WindowsSystem32driversetchosts文件中添加如下一条记录:192.168.1.131 chen
添加NuGet引用“Maikebing.Data.Taos”
using Maikebing.Data.Taos; using System; namespace TDengineTest { class Program { /// <summary> /// 时间戳计时开始时间 /// </summary> static DateTime timeStampStartTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); /// <summary> /// DateTime转换为13位时间戳(单位:毫秒) /// </summary> /// <param name="dateTime"> DateTime</param> /// <returns>13位时间戳(单位:毫秒)</returns> static long DateTimeToLongTimeStamp(DateTime dateTime) { return (long)(dateTime.ToUniversalTime() - timeStampStartTime).TotalMilliseconds; } static void Main(string[] args) { string database = "power";//"db_" + DateTime.Now.ToString("yyyyMMddHHmmss"); var builder = new TaosConnectionStringBuilder() { DataSource = "chen", DataBase = database, Username = "root", Password = "taosdata", Port = 6030 }; using (var connection = new TaosConnection(builder.ConnectionString)) { DateTime dtNow = DateTime.Now; connection.Open(); connection.CreateCommand($"drop stable {database}.meters;").ExecuteNonQuery(); connection.CreateCommand($"create stable {database}.meters (timevalue timestamp, timekey bigint, current float, voltage int) TAGS (location binary(64), groupdId int);").ExecuteNonQuery(); connection.CreateCommand($"insert into d1001 using meters TAGS('Beijng.Chaoyang', 2) values ('{ dtNow.ToString("yyyy-MM-dd HH:mm:ss.ms") }', { DateTimeToLongTimeStamp(dtNow) }, 10.2, 219)").ExecuteNonQuery(); var cmd_select = connection.CreateCommand(); cmd_select.CommandText = $"select * from meters"; var reader = cmd_select.ExecuteReader(); var d = reader.ToDataTable(); cmd_select.CommandText = $"select * from d1001"; var reader1 = cmd_select.ExecuteReader(); var d1 = reader1.ToDataTable(); connection.Close(); } Console.ReadKey(); } } }
TDengine 服务端 客户端 版本要一致
参考资料
https://github.com/maikebing/Maikebing.EntityFrameworkCore.Taos
https://juejin.cn/post/6902286172711157768
qq:505645074