2015-10-14 20:59:19 +00:00
The top level name is called a measurement. These names can contain any characters. Then there are field names, field values, tag keys and tag values, which can also contain any characters. However, if the measurement, field, or tag contains any character other than [A-Z,a-z,0-9,_], or if it starts with a digit, it must be double-quoted. Therefore anywhere a measurement name, field key, or tag key appears it should be wrapped in double quotes.
2014-12-09 16:19:43 +00:00
2015-01-05 19:10:01 +00:00
# Databases & retention policies
2014-12-29 16:05:13 +00:00
```sql
-- create a database
2015-01-05 19:10:01 +00:00
CREATE DATABASE < name >
2014-12-29 17:36:16 +00:00
2015-01-05 19:10:01 +00:00
-- create a retention policy
CREATE RETENTION POLICY < rp-name > ON < db-name > DURATION < duration > REPLICATION < n > [DEFAULT]
-- alter retention policy
ALTER RETENTION POLICY < rp-name > ON < db-name > (DURATION < duration > | REPLICATION < n > | DEFAULT)+
-- drop a database
DROP DATABASE < name >
2015-01-13 21:46:07 +00:00
-- drop a retention policy
2015-06-03 23:38:37 +00:00
DROP RETENTION POLICY < rp-name > ON < db-name >
2014-12-29 16:05:13 +00:00
```
2015-06-03 23:38:37 +00:00
where `<duration>` is either `INF` for infinite retention, or an integer followed by the desired unit of time: u,ms,s,m,h,d,w for microseconds, milliseconds, seconds, minutes, hours, days, or weeks, respectively. `<replication>` must be an integer.
If present, `DEFAULT` sets the retention policy as the default retention policy for writes and reads.
2014-12-29 16:05:13 +00:00
# Users and permissions
```sql
-- create user
2015-06-03 23:38:37 +00:00
CREATE USER < name > WITH PASSWORD '< password > '
2014-12-29 16:05:13 +00:00
2015-01-05 19:10:01 +00:00
-- grant privilege on a database
GRANT < privilege > ON < db > TO < user >
2014-12-29 16:05:13 +00:00
-- grant cluster admin privileges
GRANT ALL [PRIVILEGES] TO < user >
2014-12-29 17:36:16 +00:00
2015-01-05 19:10:01 +00:00
-- revoke privilege
REVOKE < privilege > ON < db > FROM < user >
2014-12-29 17:36:16 +00:00
-- revoke all privileges for a DB
REVOKE ALL [PRIVILEGES] ON < db > FROM < user >
2015-06-03 23:57:50 +00:00
-- revoke all privileges including cluster admin
2014-12-29 17:36:16 +00:00
REVOKE ALL [PRIVILEGES] FROM < user >
2015-06-03 23:38:37 +00:00
-- combine db creation with privilege assignment (user must already exist)
CREATE DATABASE < name > GRANT < privilege > TO < user >
CREATE DATABASE < name > REVOKE < privilege > FROM < user >
2014-12-29 17:36:16 +00:00
-- delete a user
2015-01-05 19:10:01 +00:00
DROP USER < name >
2015-06-03 23:38:37 +00:00
2014-12-29 16:05:13 +00:00
```
2015-06-10 23:10:31 +00:00
where `<privilege> := READ | WRITE | All ` .
2015-06-03 23:57:50 +00:00
Authentication must be enabled in the influxdb.conf file for user permissions to be in effect.
By default, newly created users have no privileges to any databases.
Cluster administration privileges automatically grant full read and write permissions to all databases, regardless of subsequent database-specific privilege revocation statements.
2014-12-29 16:05:13 +00:00
2014-11-25 22:27:34 +00:00
# Select
2014-12-09 15:24:35 +00:00
```sql
2017-10-25 07:05:52 +00:00
SELECT * FROM just_my_type
```
2014-11-25 22:27:34 +00:00
2017-10-25 07:05:52 +00:00
## Group By
```sql
SELECT mean(value) from cpu WHERE host = 'serverA' AND time > now() - 4h GROUP BY time(5m)
2015-01-29 21:25:12 +00:00
SELECT mean(value) from cpu WHERE time > now() - 4h GROUP BY time(5m), region
2014-12-09 15:24:35 +00:00
```
2014-11-25 22:27:34 +00:00
# Delete
2017-10-25 07:05:52 +00:00
```sql
DELETE FROM "cpu"
DELETE FROM "cpu" WHERE time < '2000-01-01T00:00:00Z'
DELETE WHERE time < '2000-01-01T00:00:00Z'
```
2014-11-25 22:27:34 +00:00
# Series
## Destroy
2014-12-09 16:19:43 +00:00
```sql
DROP MEASUREMENT < name >
DROP MEASUREMENT cpu WHERE region = 'uswest'
```
2014-11-25 22:27:34 +00:00
2015-01-29 21:25:12 +00:00
## Show
2014-11-25 22:27:34 +00:00
2015-01-29 21:25:12 +00:00
Show series queries are for pulling out individual series from measurement names and tag data. They're useful for discovery.
2014-12-09 15:49:42 +00:00
```sql
2015-01-26 03:40:50 +00:00
-- show all databases
SHOW DATABASES
2015-01-13 19:53:11 +00:00
2015-01-26 03:40:50 +00:00
-- show measurement names
SHOW MEASUREMENTS
SHOW MEASUREMENTS LIMIT 15
SHOW MEASUREMENTS LIMIT 10 OFFSET 40
SHOW MEASUREMENTS WHERE service = 'redis'
-- LIMIT and OFFSET can be applied to any of the SHOW type queries
2014-12-09 16:26:34 +00:00
2015-01-26 03:40:50 +00:00
-- show all series across all measurements/tagsets
SHOW SERIES
2014-12-09 15:49:42 +00:00
2015-01-26 03:40:50 +00:00
-- get a show of all series for any measurements where tag key region = tak value 'uswest'
SHOW SERIES WHERE region = 'uswest'
2014-12-09 15:49:42 +00:00
2015-01-26 03:40:50 +00:00
SHOW SERIES FROM cpu_load WHERE region = 'uswest' LIMIT 10
2015-01-12 21:51:56 +00:00
2015-01-26 03:40:50 +00:00
-- returns the 100 - 109 rows in the result. In the case of SHOW SERIES, which returns
2015-01-19 16:31:45 +00:00
-- series split into measurements. Each series counts as a row. So you could see only a
-- single measurement returned, but 10 series within it.
2015-01-26 03:40:50 +00:00
SHOW SERIES FROM cpu_load WHERE region = 'uswest' LIMIT 10 OFFSET 100
2015-01-19 16:31:45 +00:00
2015-01-26 03:40:50 +00:00
-- show all retention policies on a database
2015-07-22 22:46:42 +00:00
SHOW RETENTION POLICIES ON mydb
2015-01-13 20:21:06 +00:00
2015-01-26 03:40:50 +00:00
-- get a show of all tag keys across all measurements
SHOW TAG KEYS
2014-12-09 15:49:42 +00:00
2015-01-26 03:40:50 +00:00
-- show all the tag keys for a given measurement
SHOW TAG KEYS FROM cpu
SHOW TAG KEYS FROM temperature, wind_speed
2014-12-09 15:49:42 +00:00
2015-01-26 03:40:50 +00:00
-- show all the tag values. note that a single WHERE TAG KEY = '...' clause is required
2015-01-29 21:25:12 +00:00
SHOW TAG VALUES WITH TAG KEY = 'region'
SHOW TAG VALUES FROM cpu WHERE region = 'uswest' WITH TAG KEY = 'host'
2014-12-09 16:26:34 +00:00
-- and you can do stuff against fields
2015-01-26 03:40:50 +00:00
SHOW FIELD KEYS FROM cpu
2014-12-09 16:26:34 +00:00
-- but you can't do this
2015-01-26 03:40:50 +00:00
SHOW FIELD VALUES
2014-12-09 16:26:34 +00:00
-- we don't index field values, so this query should be invalid.
2015-01-14 16:53:17 +00:00
2015-01-26 03:40:50 +00:00
-- show all users
SHOW USERS
2014-12-09 15:49:42 +00:00
```
2015-01-26 03:40:50 +00:00
Note that `FROM` and `WHERE` are optional clauses in most of the show series queries.
2014-12-09 16:19:43 +00:00
2015-01-26 03:40:50 +00:00
And the show series output looks like this:
2014-12-09 15:49:42 +00:00
```json
[
{
"name": "cpu",
"columns": ["id", "region", "host"],
"values": [
1, "uswest", "servera",
2, "uswest", "serverb"
]
},
{
"name": "reponse_time",
"columns": ["id", "application", "host"],
"values": [
3, "myRailsApp", "servera"
]
}
]
```
2014-11-25 22:27:34 +00:00
# Continuous Queries
2015-10-28 06:02:18 +00:00
Continuous queries are going to be inspired by MySQL `TRIGGER` syntax:
2014-11-25 22:27:34 +00:00
http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html
Instead of having automatically-assigned ids, named continuous queries allows for some level of duplication prevention,
particularly in the case where creation is scripted.
## Create
CREATE CONTINUOUS QUERY < name > AS SELECT ... FROM ...
## Destroy
DROP CONTINUOUS QUERY < name >
## List
2015-01-26 03:40:50 +00:00
SHOW CONTINUOUS QUERIES