Documentation

Use the influxctl CLI to query data

Use the influxctl query command to query data in InfluxDB Clustered with SQL or InfluxQL.

Provide the following with your command:

  • Database token: A database token with read permissions on the queried database. By default, this uses the database setting from the influxctl connection profile or the --token command flag.

  • Database name: The name of the database to query. By default, this uses the database setting from the influxctl connection profile or the --database command flag.

  • Query language (Optional): The query language of the query. Use the --language flag to specify one of the following query languages:

    • sql (default)
    • influxql
  • Query: SQL or InfluxQL query to execute. Pass the query in one of the following ways:

    • a string on the command line
    • a path to a file that contains the query
    • a single dash (-) to read the query from stdin
influxctl query \
  --token 
DATABASE_TOKEN
\
--database
DATABASE_NAME
\
"SELECT * FROM home"
  • Copy
  • Fill window
influxctl query \
  --token 
DATABASE_TOKEN
\
--database
DATABASE_NAME
\
/path/to/query.sql
  • Copy
  • Fill window
cat ./query.sql | influxctl query \
  --token 
DATABASE_TOKEN
\
--database
DATABASE_NAME
\
-
  • Copy
  • Fill window
influxctl query \
  --token 
DATABASE_TOKEN
\
--database
DATABASE_NAME
\
--language influxql \ "SELECT * FROM home"
  • Copy
  • Fill window
influxctl query \
  --token 
DATABASE_TOKEN
\
--database
DATABASE_NAME
\
--language influxql \ /path/to/query.influxql
  • Copy
  • Fill window
cat ./query.influxql | influxctl query \
  --token 
DATABASE_TOKEN
\
--database
DATABASE_NAME
\
--language influxql \ -
  • Copy
  • Fill window

Replace the following:

  • DATABASE_TOKEN: Database token with read access to the queried database
  • DATABASE_NAME: Name of the database to query

Output format

The influxctl query command supports the following output formats:

  • table (default)
  • json

Use the --format flag to specify the output format:

influxctl query \
  --format json \
  "SELECT * FROM home WHERE time >= '2025-04-28T08:00:00Z' LIMIT 5"
  • Copy
  • Fill window

View example table-formatted results

View example JSON-formatted results

Timestamp format

When using the table output format, you can specify which of the following timestamp formats to use to display timestamp values in the query results:

influxctl query \
  --time-format unixnano \
  "SELECT * FROM home WHERE time >= '2025-04-28T08:00:00Z' LIMIT 5"
  • Copy
  • Fill window

View example results with unix nanosecond timestamps


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

Now Generally Available

InfluxDB 3 Core and Enterprise

Start fast. Scale faster.

Get the Updates

InfluxDB 3 Core is an open source, high-speed, recent-data engine that collects and processes data in real-time and persists it to local disk or object storage. InfluxDB 3 Enterprise builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries and optimized storage. A free tier of InfluxDB 3 Enterprise is available for non-commercial at-home or hobbyist use.

For more information, check out: