Query data with InfluxQL

InfluxQL reference documentation

For complete InfluxQL reference documentation, see Influx Query Language in the latest InfluxDB 1.x documentation.

To use InfluxQL to query bucket data, complete the following steps:

  1. .
  2. Map unmapped buckets.
  3. .

When upgrading from InfluxDB 1.x to 2.2, database and retention policy combinations are mapped to InfluxDB 2.2 buckets. For more information, see . If you’re not sure how data was written into a bucket, verify the bucket has a mapping.

Use the influx CLI or the to verify the buckets you want to query are mapped to a database and retention policy.

influx CLI

Use the influx v1 dbrp list command to list DBRP mappings.

View all DBRP mappings
Filter DBRP mappings by database
  1. influx v1 dbrp list --db example-db
Filter DBRP mappings by bucket ID
  1. influx v1 dbrp list --bucket-id 00oxo0oXx000x0Xo

Use the /api/v2/dbrps API endpoint to list DBRP mappings. Include the following:

  • Request method: GET
  • Headers:
    • Authorization: Token schema with your InfluxDB
  • Query parameters:
    * Required
    • * orgID: organization ID
    • bucketID: (to list DBRP mappings for a specific bucket)
    • database: database name (to list DBRP mappings with a specific database name)
    • rp: retention policy name (to list DBRP mappings with a specific retention policy name)
    • id: DBRP mapping ID (to list a specific DBRP mapping)
View all DBRP mappings
Filter DBRP mappings by database
  1. http://localhost:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo&db=example-db \
  2. --header "Authorization: Token YourAuthToken"
Filter DBRP mappings by bucket ID
  1. curl --request GET \
  2. https://cloud2.influxdata.com/api/v2/dbrps?organization_id=00oxo0oXx000x0Xo&bucketID=00oxo0oXx000x0Xo \
  3. --header "Authorization: Token YourAuthToken"

If you do not find a DBRP mapping for a bucket, complete the next procedure to map the unmapped bucket. For more information on the DBRP mapping API, see the .

Use the influx CLI or the to manually create DBRP mappings for unmapped buckets.

influx CLI

Use the influx v1 dbrp create command to map an unmapped bucket to a database and retention policy. Include the following:

* Required

  • * org and token to authenticate. We recommend setting your organization and token to your active InfluxDB connection configuration in the influx CLI, so you don’t have to add these parameters to each command. To set up your active InfluxDB configuration, see .
  • * database name to map
  • * retention policy name to map
  • * Bucket ID to map to
  • Default flag to set the provided retention policy as the default retention policy for the database
  • Request method: POST
  • Headers:
    • Authorization: Token schema with your InfluxDB
    • Content-type: application/json
  • Request body: JSON object with the following fields:
    * Required
    • * bucketID: bucket ID
    • * database: database name
    • default: set the provided retention policy as the default retention policy for the database
    • * org or orgID: organization name or
    • * retention_policy: retention policy name
  1. --header "Authorization: Token YourAuthToken" \
  2. --header 'Content-type: application/json' \
  3. --data '{
  4. "bucketID": "00oxo0oXx000x0Xo",
  5. "database": "example-db",
  6. "default": true,
  7. "orgID": "00oxo0oXx000x0Xo",
  8. }'

After you’ve verified the bucket is mapped, query the bucket using the query 1.x compatibility endpoint.

The InfluxDB 1.x compatibility API supports all InfluxDB 1.x client libraries and integrations in InfluxDB OSS 2.2.

To query a mapped bucket with InfluxQL, use the . Include the following in your request:

  • Request method: GET
  • Headers:
  • Query parameters:
    • db: 1.x database to query
    • rp: 1.x retention policy to query (if no retention policy is specified, InfluxDB uses the default retention policy for the specified database)
    • q: URL-encoded InfluxQL query

URL-encode query parameters that may contain whitespace or other special characters.

  1. curl --get http://localhost:8086/query?db=example-db \
  2. --header "Authorization: Token YourAuthToken" \
  3. --data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"

By default, the /query compatibility endpoint returns results in JSON. To return results as CSV, include the header.

InfluxDB OSS 2.2 supports InfluxQL read-only queries. See supported and unsupported queries below. To learn more about InfluxQL, see .

Supported InfluxQL queries
  • DELETE*
  • DROP MEASUREMENT*
  • EXPLAIN ANALYZE
  • SELECT (read-only)
  • SHOW DATABASES
  • SHOW MEASUREMENTS
  • SHOW TAG KEYS
  • SHOW TAG VALUES
  • SHOW FIELD KEYS
Unsupported InfluxQL queries
  • SELECT INTO
  • ALTER
  • CREATE
  • DROP (limited support)
  • GRANT
  • KILL