阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

使用influx控制台工具操作InfluxDB

163次阅读
没有评论

共计 4504 个字符,预计需要花费 12 分钟才能阅读完成。

这里记录下 influx 控制台的简单使用,如需更多功能请参考 InfluxDB 官方文档:https://docs.influxdata.com/influxdb/v1.1/

环境:CentOS6.5_x64
InfluxDB 版本:1.1.0

准备工作

  • 启动服务器

执行如下命令:

service influxdb start

示例如下:

[root@localhost ~]# service influxdb start
Starting influxdb...
influxdb process was started [OK]
[root@localhost ~]#
  • 启动控制台客户端

在控制台执行 influx 即可启动 InfluxDB cli,示例如下:

[root@localhost ~]# influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.1.0
InfluxDB shell version: 1.1.0
>

influx 控制台基本操作

数据库操作

  • 显示已存在的所有数据库

格式:show databases
示例如下:

> show databases;
name: databases
name
----
_internal
  • 创建新数据库

格式:

create database <dbname>

说明:
dbname : 数据库名称
示例如下:

> create database testdb;
> show databases;
name: databases
name
----
_internal
testdb
>
  • 删除数据库

格式:

drop database <dbname>

说明:
dbname : 数据库名称
示例如下:

> drop database testdb;
> show databases;
name: databases
name
----
_internal

>

表操作

  • 显示指定数据库中已存在的表

格式:show measurements
示例如下:

> use testdb;
Using database testdb
> show measurements;
  • 创建新表并添加数据

InfluxDB 没有提供单独的建表语句,可以通过以下方式创建数据库并添加数据。

格式:

insert <tbname>,<tags> <values> [timestamp]

说明:
tbname : 数据表名称
tags : 表的 tag 域
values : 表的 value 域
timestamp:当前数据的时间戳(可选,没有提供的话系统会自带添加)

示例如下:

> use testdb;
Using database testdb
> insert students,stuid=s123 score=89
> show measurements;
name: measurements
name
----
students
  • 删除表

格式:

drop measurement  <tbname>

说明:
tbname : 数据表名称

示例如下:

> use testdb;
Using database testdb
> drop measurement students;
> show measurements;
>

数据操作

  • 添加

格式:

insert <tbname>,<tags> <values> [timestamp]

说明:
tbname : 数据表名称
tags : 表的 tag 域
values : 表的 value 域
timestamp:当前数据的时间戳(可选,没有提供的话系统会自带添加)

示例如下:

> insert students,stuid=s123 score=79
> insert students,stuid=s123 score=89  1488821368327436809
> select * from students
name: students
time                    score   stuid
----                    -----   -----
1488821368327436809     89      s123
1488821404414227498     79      s123
  • 查询

格式:

select <fields> from <tbname> [into_clause] [where_clause]              
          [group_by_clause] [order_by_clause] [limit_clause]              
          [offset_clause] [slimit_clause] [soffset_clause]     

说明:
fields : 要查询的字段,查询全部可以用 *
tbname : 数据表名称
into_clause : select … into(可选)
where_clause : where 条件域(可选)
group_by_clause : group by 相关(可选)
order_by_clause : order by 相关(可选)
limit_clause : limit 相关(可选)
offset_clause : offset 相关(可选)
slimit_clause : slimit 相关(可选)
soffset_clause : soffset 相关(可选)

示例如下:

> use testdb;
Using database testdb
> show measurements;
name: measurements
name
----
students

> select * from students
name: students
time                    score   stuid
----                    -----   -----
1488821368327436809     89      s123
1488821404414227498     79      s123
1488822192864587535     69      s123
1488822196951305763     39      s123

> select * from students where score > 70;
name: students
time                    score   stuid
----                    -----   -----
1488821368327436809     89      s123
1488821404414227498     79      s123

> select * from students where score > 70 limit 1;
name: students
time                    score   stuid
----                    -----   -----
1488821368327436809     89      s123

>
  • 更新

tags 和 timestamp 相同时数据会执行覆盖操作,相当于 InfluxDB 的更新操作。

示例如下:

> insert students,stuid=s123 score=39
> select * from students
name: students
time                    score   stuid
----                    -----   -----
1488822338410283027     39      s123

> insert students,stuid=s123 score=99 1488822338410283027
> select * from students
name: students
time                    score   stuid
----                    -----   -----
1488822338410283027     99      s123

>
  • 删除

格式:

delete from <tbname> [where_clause]

说明:
tbname : 表名称
where_clause : where 条件(可选)

删除所有数据:

> delete from students;
> select * from students;
>

删除指定条件的数据:

> select * from students;
name: students
time                    score   stuid
----                    -----   -----
1488820352594964019     89      s123
1488820356463338534     79      s123


> delete from students where stuid='s123' and time=1488820352594964019;
> select * from students;
name: students
time                    score   stuid
----                    -----   -----
1488820356463338534     79      s123

>

其它

  • 控制台执行单次查询

格式:

influx -execute '<query>'

类似 mysql -e 的功能,示例代码如下:

[root@localhost ~]# influx -execute 'show databases'
name: databases
name
----
_internal
testdb

[root@localhost ~]#
  • 指定查询结果以 csv 或 json 格式输出

格式:

influx -format=[format]

说明:

format:启动格式,支持 column,csv,json 三种格式,默认为 column

示例如下:

[root@localhost ~]# influx -format=csv
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.1.0
InfluxDB shell version: 1.1.0
> show databases;
name,name
databases,_internal
databases,testdb
> exit
[root@localhost ~]# influx -format=json
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.1.0
InfluxDB shell version: 1.1.0
> show databases;
{"results":[{"series":[{"name":"databases","columns":["name"],"values":[["_internal"],["testdb"]]}]}]}
> exit
[root@localhost ~]# influx -format=json -pretty
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.1.0
InfluxDB shell version: 1.1.0
> show databases;
{"results": [
        {"series": [
                {"name": "databases",
                    "columns": ["name"
                    ],
                    "values": [
                        ["_internal"
                        ],
                        ["testdb"
                        ]
                    ]
                }
            ]
        }
    ]
}

好,就这些了,希望对你有帮助。

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141536.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-22发表,共计4504字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中