Influxdb Tutorial

Influxdata is a platform for storing, collecting, visualizing and managing time-series data. It is faster than mysql. Currently Influxdb is the most famous time series database. In influxdb time is the primary key. So lets start.

Install influxd
After installing start its service

sudo influxd

The service will be started.
Now open another terminal and start the CLI using command influx

$ influx
Connected to http://localhost:8086 version 0.13.x
InfluxDB shell 0.13.x

First create a database

> create database mydb

To view the list of databases

> show databases
name: databases


For using the database

> use mydb

Note : In influxdb we call tables as measurements and columns as fields.

We don’t need to define measurements(tables) and fields(columns). It will create measurements and add columns automatically when we insert data.

Inserting Data

Format for writing data is

measurementName field1=value1,field2=value2,field3=value3 timestamp
  • The timestamp is in nanoseconds. If we don’t provide timestamp it will assign the local current timestamp.
  • By default it assumes all the numbers as doubles. For integer value we have to append i at the end.
    > insert measurementName field4=12i
  • String values should be in double quotes.
    > insert measurementName field5="qwqw"
  • For boolean values use t, T, true, True, or TRUE for TRUE, and f, F, false, False, or FALSE for FALSE
    > insert measurementName field6=T
  • We can use \ character for escaping comma, space, equal and other special character in field (field) value

For more details refer official documentation

Querying Data

To select all fields from measurement

> select * from measurementName

To select particular fields

> select field1, field2 from measurement

Note : If your mesurement name or field name contains characters such as .# or =, then use double quotes

> select "", "" from ""

Where clause

A typical usage of where clause

> select * from measurement where field1 > 12 and field2 = 'sparta' and time > now() - 1d

We can also use or logic using separaters ( and ).

Supported comaparaters in influxdb are

  • = equal to
  • <> not equal to
  • != not equal to
  • > greater than
  • < less than
  • =~ matches against
  • !~ doesn’t match against

You can read about queries in details from its website

4 thoughts on “Influxdb Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *