Python3使用TDengine的配置
参考资料:https://github.com/taosdata/TDengine/issues/10072参考资料:https://www.taosdata.com/docs/cn/v2.0/connector#python1.Server端需要的信息1.Server的IP地址及端口host = "x.xx.xxx.250:6030[root@tdnode1 ~]# taosd | grep -
·
参考资料:https://github.com/taosdata/TDengine/issues/10072
参考资料:https://www.taosdata.com/docs/cn/v2.0/connector#python
1.Server端需要的信息
1.Server的IP地址及端口
host = "x.xx.xxx.250:6030
[root@tdnode1 ~]# taosd | grep -i fqdn
fqdn = tdnode1.xxx.com
2.client端的配置
1,安装客户端或服务端
2,配置客户端
2.1 修改hosts
ubuntu@10-23-46-1:~$ sudo nano /etc/hosts
127.0.0.1 localhost
#增加这一行
x.xxx.xxx.250 tdnode1.xxx.com
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 10-23-46-1 10-23-46-1
2.2修改taos.cfg
ubuntu@10-23-46-1:~$ sudo nano /etc/taos/taos.cfg
#修改内容
# first fully qualified domain name (FQDN) for TDengine system
firstEp tdnode1.xxxx.com:6030
# local fully qualified domain name (FQDN)
fqdn tdnode1.xxxx.com:6030
# first port number for the connection (12 continuous UDP/TCP port number are used)
# serverPort 6030
3.安装python驱动
pip3 install taospy
import taos
例子
import taos
conn = taos.connect(host="x.xxx.xxx.250:6030", user="root", password="taosdata",config="/etc/taos")
c1 = conn.cursor()
import datetime
# 创建数据库
c1.execute('create database db')
c1.execute('use db')
# 建表
c1.execute('create table tb (ts timestamp, temperature int, humidity float)')
# 插入数据
start_time = datetime.datetime(2019, 11, 1)
affected_rows = c1.execute('insert into tb values (\'%s\', 0, 0.0)' %start_time)
# 批量插入数据
time_interval = datetime.timedelta(seconds=60)
sqlcmd = ['insert into tb values']
for irow in range(1,11):
start_time += time_interval
sqlcmd.append('(\'%s\', %d, %f)' %(start_time, irow, irow*1.2))
affected_rows = c1.execute(' '.join(sqlcmd))
更多推荐
已为社区贡献1条内容
所有评论(0)