InfluxDB用Go语言编写的一个开源分布式时序、事件和指标数据库。
安装使用
安装
1 2 3
| sudo apt update sudo apt install influxdb sudo apt install influxdb-client
|
启动
1 2
| sudo service influxdb start sudo service influxdb status
|
进入命令行
1 2 3 4
| $ influx Connected to http://localhost:8086 version 1.6.4 InfluxDB shell version: 1.6.4 >
|
创建数据库
1 2 3 4 5 6 7
| > create database testdb > show databases name: databases name
_internal testdb
|
选择数据库
1 2
| > use testdb Using database testdb
|
名词解释
假定有一张表weather用于记录:多个地区在几组海拔下的一天的温度变化,所以表中有以下字段:
- 时间 time
- 温度 temperature
- 湿度 humidity
- 地区 area
- 海拔 altitude
与传统数据库中的名词做比较
influxDB中的名词 |
传统数据库中的概念 |
database |
数据库 |
measurement |
数据库中的表 |
points |
表里面的一行数据 |
InfluxDB中独有的一些概念
Point由时间戳(time)、数据(field)、标签(tags)组成。
Point属性 |
传统数据库中的概念 |
time |
每个数据记录时间,是数据库中的主索引(会自动生成) |
fields |
各种记录值(没有索引的属性)也就是记录的值:温度, 湿度 |
tags |
各种有索引的属性:地区,海拔 |
series表示这个表里面的数据可以在图表上画成几条线:通过tags排列组合算出来。
比如有如下数据:
1 2 3 4 5 6 7 8 9 10 11 12
| > select * from weather name: weather ------------- time altitude area humidity temperature 1456386985094000000 1000 北 18 17 1456386985094000000 5000 上 20 47 1456386985094000000 5000 北 26 68 1456386985094000000 1000 广 17 83 1456387267668000000 1000 上 12 77 1456387267668000000 1000 北 16 20 1456387267668000000 5000 广 -3 66 1456387267668000000 5000 上 19 60
|
它的series为:
1 2 3 4 5 6 7 8 9 10
| > show series from weather name: weather ------------- _key altitude area weather,altitude=1000,area=北 1000 北 weather,altitude=5000,area=北 5000 北 weather,altitude=5000,area=上 5000 上 weather,altitude=1000,area=广 1000 广 weather,altitude=1000,area=上 1000 上 weather,altitude=5000,area=广 5000 广
|