InfluxDB uselful queries

Show all available databases
show databases

Use a database e.g mydb
use mydb

Show available fields and their type of a a database
show field keys

Show series where xyz
show series where "powermeter" = 'xyzzz'

Calculate difference between the two latest values of two days
SELECT difference(last(total_kWh)) FROM power_total WHERE time >0 AND "powerMeter" = 'xyz' GROUP BY time(1d)

Select the latest entries from a field within a timespan of 2 days
select * from inputs WHERE time >= now() -2d
select * from inputs WHERE time >= now - 10m

Write measurement / series in database. Select database first. Tag Keys are not required
INSERT TheMeasurement value=10

Select last 10 entries
SELECT * FROM measurement ORDER BY desc LIMIT 10

Rename measurement. Not supported by influx. Copy into a new one is they way. To preserve tags, use group by *
SELECT * INTO DestMeasurementCopy from SrcMeasurement GROUP BY *
DROP MEASUREMENT SrcMeasurement

Drop a measurement
DROP MEASUREMENT measurement_name

Grant user all rights on database
GRANT ALL ON "powermeter" to "myUser"

Grant user read rights on database
GRANT READ ON "powermeter" to "myGrafanaUser"

Show rights of a user
SHOW GRANTS for myUser

Create user with password
CREATE USER "myUser" WITH PASSWORD thepassword

Create user with all privileges
CREATE USER admin WITH PASSWORD mypw WITH ALL PRIVILEGES

Show all users
SHOW USERS

Create a database
CREATE DATABASE powermeter

Delete database
DROP DATABASE myDatabase


Kommentare

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert