WRITELOOP

INFLUXDB CLI CHEATSHEET

2018 January 11

InfluxDB CLI Cheatsheet

Connect to influx:

$ influx

Note: There is another CLI to influx that can be installed through python pypi. You can search there for influx-prompt. It does not coexist very well with other db CLIs like mycli or pgcli, so you probably should install it on a separate virtualenv.

Get all databases available:

$ SHOW DATABASES

Connect to a database:

$ USE collectd;

Get all measurements from database:

$ SHOW MEASUREMENTS

Get all data from a specific measurement:

$ SELECT * FROM memory_value;

Get metric aggregated per 20 minutes:

SELECT time, mean(value)/1000000 AS mean_value_in_mb FROM memory_value WHERE type_instance = 'free' GROUP BY time(20m) ORDER BY time DESC;
(GROUP BY queries imply an aggregation - in this case, mean(value). It could be count(value), etc...)

Show time column as human-readable timestamp:

$ PRECISION RFC3339

BACKUP / RESTORE

BACKUP:

$ influxd backup -database collectd /tmp/influxdb.backup
$ influxd backup -database collectd -start 2017-04-28T06:49:00Z -end 2017-04-28T06:50:00Z /tmp/influxdb.backup

RESTORE:

$ sudo influxd restore -database collectd -datadir /var/lib/influxdb/data /tmp/influxdb.backup/

CREATE AN ADMIN USER TO PROTECT YOUR DATABASE:

$ influx -execute "CREATE USER admin WITH PASSWORD 'mysecret' WITH ALL PRIVILEGES";

You must also edit influxdb.conf and enable the authentication there. After that, you will not be able to do queries on influx cli without specifying the username and password. You will be able to connect to influx, but all operations will return errors. Below are some examples on how to access the cli, one to enter commands interactively and another to run a specific command and quit.

$ influx -username admin -password mysecret
$ influx -username admin -password mysecret -execute "SHOW USERS";