一、简介
Influxdb是一个时序数据库(Time Series Database),适合保存按照时间顺序打点的数据,例如监控信息、日志信息、统计信息等。
官网:https://www.influxdata.com/
二、安装、启动
Mac上安装
brew install influxdb
启动和停止
brew services start influxdb
brew services stop influxdb
上面是后台启动,或者直接前台启动,可以看到输出到console的日志:
influxd
三、基本概念
Influxdb和MySQL很像,不管是db、table的概念,还是SQL语句查询,都很相像。
- 数据库 - database
- 表 - measurement
- 列 - tag
- 值 - value
四、客户端连接
连接
- 连接到本地服务
➜ influx
Connected to http://localhost:8086 version v1.6.3
InfluxDB shell version: v1.6.3
> exit
- 连接到远端服务器的 influxdb 服务
influx -database 'db_name' -host '198.1.1.1' -port '8086'
Connected to http://198.1.1.1:8086 version 1.5.4
InfluxDB shell version: v1.6.3
> exit
五、基本增删查命令
增
> create database db_test
> show databases
name: databases
name
----
_internal
db_test
> use db_test
Using database db_test
> insert measurement_test,tag_a="abc",tag_b="def" count1=123,count2=456,count3=789
> insert measurement_test,tag_a="abc",tag_b="def" count1=123,count2=456,count3=789
> insert measurement_test,tag_a="cba",tag_b="def" count1=123,count2=456,count3=789
> show measurements
name: measurements
name
----
measurement_test
>
查
> show measurements
name: measurements
name
----
measurement_test
> select * from measurement_test
name: measurement_test
time count1 count2 count3 tag_a tag_b
---- ------ ------ ------ ----- -----
1547618434743359000 123 456 789 "abc" "def"
1547618524727590000 123 456 789 "abc" "def"
1547619061163184000 123 456 789 "cba" "def"
> select sum(count1) from measurement_test group by tag_a
name: measurement_test
tags: tag_a="abc"
time sum
---- ---
0 246
name: measurement_test
tags: tag_a="cba"
time sum
---- ---
0 123
删
> delete from measurement_test where tag_a="cba"
> drop measurement measurement_test
> show measurements
> drop database db_test
> show databases
name: databases
name
----
_internal
改
不支持改
SELECT, DELETE, SHOW, CREATE, DROP, EXPLAIN, GRANT, REVOKE, ALTER, SET, KILL
注:
- 不支持修改,只支持 select、delete、show、create、drop、explain、grant、revoke、alter、set、kill 这几个关键字;
- 聚合的时候,不需要在 select 里加上要聚合的字段,直接放到 group by 里即可;
网友评论