InfluxDB first experience

What is time series data? The simplest definition is the data in the data format that contains the timestamp field. For example, the price of the stock market, the temperature in the environment, the CPU usage of the host, and so on. But what data does not contain timestamp? Almost all data can be tagged with a timestamp field. One of the more important attributes of time series data is how to query it. At the time of the query, we always bring a time range to filter the data for the time series. At the same time, the result of the query will always include the timestamp field.

basic concept

nouns in influxDB Concepts in traditional databases
database database
measurement Tables in the database
points One row of data in the table


A Point consists of a time, a field, and a tag.

Point is equivalent to a row of data in a traditional database, as shown in the following table:

Point Properties Concepts in Traditional Databases
time each data record time, is the main index in the database (will be automatically generated)
fields various record values ​​(properties without indexes) are also recorded values: temperature, humidity
tags Various indexed properties: region, altitude


Quick installation

influxdb docker container running

 Docker run -p 8086:8086 -d --name influxdb -v /data/docker_volumes/influxdb:/var/lib/influxdb influxdb

For the docker operation, please refer to my previous article:

Basic operation

Console command

Shell command official documentation reference:

docker exec -it influxdb influx Execute the influx command in the container running above, enter the influxdb interactive command line as follows:

[zhipeng.zhou@instance-1 ~]$ docker exec -it influxdb influx
Connected to http://localhost:8086 version 1.5.1
InfluxDB shell version: 1.5.1

Similar to mysql, we first create a test library using create database test, then use show databases to view the list of existing databases:

> create database test
> show databases
Name: databases

Datasheet operation

In InfluxDB, there is no concept of table. Instead, MEASUREMENTS, the function of MEASUREMENTS is consistent with the table in the traditional database, so we can also refer to MEASUREMENTS as a table in InfluxDB.


英[‘meʒəm(ə)nts] 美[‘mɛʒɚmənts]

  • n. measured value, size (multiple of measurement)

1) Display all tables SHOW MEASUREMENTS

ERR: database name required
Warning: It is possible this error is due to not setting a database.
Please set a database with the command "use <database>".

An error occurred, the prompt must first use , the same as mysql:

> use test
Using database test

The target does not have any tables, then we try to create one.

2) Create a table (create ??)

Since there is no explicit statement for creating a new table in InfluxDB, the new table can only be created by means of insert data. As follows:

Insert cpu_usage,ip= value=30 15226580942111

** Note that there is no into! after the insert here!!

Where cpu_usage is the name of the table, ip is the tag index, value=xx is the record value key-value pair, the record value can have more than one, and finally the specified time, the data just inserted under the query:

> select * from cpu_usage
Name: cpu_usage
Time ip value
---- -- -----
15226580942111 30

3) Delete table (drop measurement cpu_usage)

Data manipulation

1) Add data

A row of data represents a Point (see the basic concept above), and the insert syntax is summarized:

insert [,=...] =[,=...] [unix-nano-timestamp]

Description: We can not include a timestamp when writing. When there is no timestamp, InfluxDB will automatically add the local current time as its timestamp.

2) Query operation

The query statement is the same as SQL and will not be described here.

3) Modify and delete data

InfluxDB is a time series database and does not provide a way to modify and delete data.

But deletion can be achieved through InfluxDB’s Retention Policies. Explain separately in subsequent tutorials.

to sum up

The above is just a preliminary experience, more about the other features of influxdb, will be introduced in the following articles.

Last modified: 2019年3月29日




    在docker上安装influxdb真所谓是一波三折,各种报错,网上对报错的资料见解也很少,感谢您的分享,赞一波!! :biggrin:


感谢分享!已推荐到《开发者头条》: 欢迎点赞支持!
使用开发者头条 App 搜索 185910 即可订阅《CodingAir》

Write a Reply or Comment

Your email address will not be published.