連接 InfluxDB
# influx -precision rfc3339
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
>
1. influx 透過InfluxDB API 連接數據庫
2. 預設端口 8086
3. -precision rfc3339 設定timestamp 格式(YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ).
建立數據庫
> create database mydb
列出數據庫
> show databases
name: databases
name
----
_internal
mydb
>
連接數據庫
> use mydb
Using database mydb
寫入數據
寫入數據格式:
<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]
Influx | SQL | Description | value |
---|---|---|---|
<measurement> | 表格名稱 | 文字 | 必要 |
tag | 欄位 | 可以當索引, key-value格式 | 選項 |
field | 欄位 | 無法當索引 , key-value格式 | 必要,最少需要1個欄位 |
unix-nano-timestamp | 時間 | 預設必要欄位 | 選項,預設使用伺服器時間 |
數據寫入 ( 透過 command line interface (CLI)
輸入5筆 XYZ/ABC 地區天氣資料 (溫度/濕度)
> use mydb
Using database mydb
> insert weather,area=XYZ temperature=10,humidity=30
> insert weather,area=ABC temperature=3,humidity=20
>
> insert weather,area=XYZ temperature=11,humidity=35
> insert weather,area=ABC temperature=4,humidity=2
>
> insert weather,area=XYZ temperature=10,humidity=40
> insert weather,area=ABC temperature=5,humidity=20
>
> insert weather,area=XYZ temperature=13,humidity=30
> insert weather,area=ABC temperature=8,humidity=20
>
> insert weather,area=XYZ temperature=10,humidity=30
> insert weather,area=ABC temperature=13,humidity=20
>
查詢數據 (查詢所有數據)
> select * from weather
name: weather
time area humidity temperature
---- ---- -------- -----------
2020-03-02T16:12:39.715326719Z XYZ 30 10
2020-03-02T16:12:40.549358988Z ABC 20 3
2020-03-02T16:12:47.471073272Z XYZ 35 11
2020-03-02T16:12:47.808673897Z ABC 2 4
2020-03-02T16:12:55.252790089Z XYZ 40 10
2020-03-02T16:12:55.965642244Z ABC 20 5
2020-03-02T16:13:00.860471861Z XYZ 30 13
2020-03-02T16:13:01.061372114Z ABC 20 8
2020-03-02T16:13:05.707889875Z XYZ 30 10
2020-03-02T16:13:06.046939017Z ABC 20 13
>
查詢數據 (查詢 XYZ 區域數據2筆)
> select * from weather where area='XYZ' LIMIT 2
name: weather
time area humidity temperature
---- ---- -------- -----------
2020-03-02T16:12:39.715326719Z XYZ 30 10
2020-03-02T16:12:47.471073272Z XYZ 35 11
原始文章(https://docs.influxdata.com/influxdb/v1.7/introduction/getting-started/)