influxdb使用命令实现crud操作
Posted 健康平安的活着
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了influxdb使用命令实现crud操作相关的知识,希望对你有一定的参考价值。
一 实现crud操作
1.1 登录数据库模式
[root@192 influxdb]# influx -username influxdb-jurf -password 'jurf-123'
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
1.2 创建数据库
> show databases;
name: databases
name
----
_internal
> create database huidian_db
> show databases;
name: databases
name
----
_internal
huidian_db
> use huidian_db
Using database huidian_db
1.3 创建表并插入数据
> insert hd_tb,name=beijing scoreval=789.56
> show measurements;
name: measurements
name
----
hd_tb
> select * from hd_tb;
name: hd_tb
time name scoreval
---- ---- --------
1621767933327483214 beijing 789.56
> insert hd_tb,name=beijing,age=12,sex='男' scoreval=789.564
> select * from hd_tb;
name: hd_tb
time age name scoreval sex
---- --- ---- -------- ---
1621767933327483214 beijing 789.56
1621768625997578434 12 beijing 789.564 '男'
1.4 保护策略
1.4.1 查看保护策略
> show retention policies on huidian_db
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
1.4.2 创建新的保护策略
> create retention policy "7hours" on huidian_db duration 7h replication 1 default
> show retention policies on huidian_db
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 false
7hours 7h0m0s 1h0m0s 1 true
1.4.3 修改保护策略
> alter retention policy "7hours" on huidian_db duration 2w replication 1 default
> show retention policies on huidian_db
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 false
7hours 336h0m0s 1h0m0s 1 true
1.4.4 查看数据
因为之前插入数据是在autogen这种永久的保护策略下,现在改为了7hours,查询数据时将没有数据,只能以select * from “策略名”.表名 这个中格式进行查询,如下图
> select * from hd_tb;
> select * from "hd_tb".autogen;
ERR: retention policy not found: hd_tb
> select * from "autogen".hd_tb;
name: hd_tb
time age name scoreval sex
---- --- ---- -------- ---
1621767933327483214 beijing 789.56
1621768625997578434 12 beijing 789.564 '男'
1.4 查询语句
> select * from hd_tb where "name"='henan'
name: hd_tb
time age name scoreval sex
---- --- ---- -------- ---
2021-05-23T12:26:12.872846386Z 67 henan 8 'nv'
> select * from "hd_tb" where sex='nv'
name: hd_tb
time age name scoreval sex
---- --- ---- -------- ---
2021-05-23T12:32:47.158042046Z 67 henan 8 nv
以上是关于influxdb使用命令实现crud操作的主要内容,如果未能解决你的问题,请参考以下文章
4_InfluxDB学习之InfluxDB的基本概念InfluxDB中独有的概念(Point,series),InfluxDB学习之InfluxDB的基本操作,InfluxDB操作方式,crud(代码