Explainer
Why the InfluxDB 2.x CLI rejects 1.8 syntax and the fix
Short answer
A 2.x InfluxDB CLI has no -execute or -database option grammar; it runs Flux. Keep InfluxQL only through the 1.x /query HTTP endpoint on InfluxDB Cloud and OSS 2.4 and later, with a database-to-bucket mapping in place; otherwise rewrite the query as a Flux pipeline over the bucket.

On this page
A batch file built around the InfluxDB 1.8 CLI stops dead on a 2.x install: the 2.x CLI parses Flux and carries no -execute or -database option grammar, so the old line fails before any query runs. Backward compatibility exists, but it is not a CLI flag. It is the separate 1.x /query HTTP endpoint, documented for InfluxDB Cloud and OSS 2.4 and later, and it needs a database-to-bucket mapping to work. On OSS builds before 2.4, and for the long term everywhere, the supported path is rewriting the query as a Flux pipeline against the bucket. This article maps each layer of the old call to its 2.x replacement and works through the exact rewrite of a win_cpu mean query.
Why the 1.8 batch call fails on a 2.x CLI #
The failing call stacks four layers that 2.x replaces at once:
- The option grammar:
-executeand-databasebelong to the 1.8 executable. The 2.x CLI's parser has neither flag; it expects a Flux query. - The query language: the
select mean(*) from win_cpu where time > ... and time < ...text is InfluxQL. The 2.x CLI speaks Flux. - The data container: a 1.8 database becomes a 2.x bucket, addressed inside the query, not by an option.
- The session:
influx.exe -execute "use telegraf"starts and exits one process; the following line starts a second one, so theuse telegrafsession state never carries over. Even under 1.8 that line was redundant, because the-databaseoption on the next line already selected the database. The rewrite keeps container selection inside the Flux query and drops the separate selection process entirely.
One independent failure source sits in the batch text itself: typographic quotation marks around paths and arguments, copied from formatted output, are not valid batch delimiters. Windows cmd needs ordinary ASCII double quotes, and a batch file that mixes the two can fail in ways that look like a version problem.
The documented backward-compatibility path #
InfluxData documents the 1.x /query compatibility endpoint for querying data with InfluxQL on InfluxDB Cloud and InfluxDB OSS 2.4 and later. That is the supported way to keep an InfluxQL script running against a 2.x server, and it works over HTTP, not through the 2.x CLI.
Two prerequisites decide whether it returns data. The 1.x data must first have been moved into buckets on the 2.x server, which is its own migration step; the walkthrough of that move is in the guide on migrating InfluxDB 1.x data into 2.x buckets. And the endpoint addresses data by the 1.x database and retention-policy names, so the old database name must be mapped to the bucket; the setup for that mapping is covered in the procedure for configuring a database and retention-policy mapping for InfluxQL.
The decision follows from the documented scope: on InfluxDB Cloud or OSS 2.4 and later, the endpoint is the short-term home for InfluxQL scripts. On OSS builds before 2.4, Flux is the documented query path, and a script built on the endpoint is borrowing a route the release does not promise.
How each layer of the old call maps to 2.x #
| Layer | 1.8 form | 2.x replacement | What to verify |
|---|---|---|---|
| Executable | influx.exe with -execute and -database |
the 2.x CLI, whose query operation takes Flux text | the resolved executable reports the 2.x version; a 1.x report means the path still selects the old binary |
| Connection | -database option carries the database name |
the CLI's own connection settings: server address, API token, organization | read them from the working 2.x configuration, never copied from the 1.8 call |
| Container | database telegraf |
bucket telegraf |
the migrated data is readable in that bucket under the job's token |
| Selection | use telegraf in its own process |
from(bucket:) inside the query |
no separate selection process exists |
| Language | InfluxQL select mean(*) from win_cpu ... |
Flux pipeline | results compared per field and tag set |
A bucket name matching the old database name proves nothing by itself. A matching name appears when someone created a fresh bucket during the upgrade just as easily as when the 1.x data was mapped into it, so confirm the win_cpu records are actually there before touching the query text.
Rewriting the win_cpu mean query as Flux #
The inputs, and where each comes from:
- Bucket:
telegraf— the old call's-database "telegraf", carried over as the bucket the 1.x data was mapped into. - Measurement:
win_cpu— the measurement in the oldfrom win_cpuclause. - Window: an example start of
2022-08-01T12:00:00Zand stop of2022-08-01T12:30:00Z, written in RFC3339, the timestamp form Flux requires. These two values illustrate the shape; the batch substitutes its own arguments. - Aggregation: a mean over the fields in
win_cpu, standing in for the oldmean(*).
The rule in words: Flux is a pipeline. It reads points from a named bucket, bounds them to a time range, keeps only the points whose _measurement equals win_cpu, averages what survives, and labels the output.
The arithmetic written out — this is the one real difference between the two calls. The old InfluxQL predicates are strict on both ends: time > '%start%' and time < '%end%' excludes any sample stamped exactly at the start and any stamped exactly at the stop. Flux's range(start:, stop:) includes the start boundary and excludes the stop boundary. So take a sample stamped exactly 2022-08-01T12:00:00Z, the start of the example window: the 1.8 call counts it 0 times, the Flux pipeline counts it 1 time, and the Flux mean aggregates exactly one more sample than the old query whenever a sample lands on the start boundary. At the stop boundary the two agree — both exclude it.
The rewritten query, with the example window filled in:
from(bucket: "telegraf")
|> range(start: 2022-08-01T12:00:00Z, stop: 2022-08-01T12:30:00Z)
|> filter(fn: (r) => r._measurement == "win_cpu")
|> mean()
|> yield(name: "_results")
Result: one mean per input table, not one row. Flux separates points into tables by field and tag set, and each table's mean lands in the _value column; the old mean(*) had collapsed the fields into columns of a single result. The row counts will not match, and they are not supposed to.
The decision it leads to, with its threshold: run the pipeline through range() and the win_cpu filter first and confirm raw, unaggregated records come back — an empty result at that stage indicts the bucket mapping, the timestamps, the measurement name or the access context, never the aggregation. Add mean() only after that passes. Accept the rewrite when every field's mean matches a verified 1.8 reference window, allowing one specific difference: a gap that appears only when a sample sits exactly on the start boundary, and that closes when you exclude that boundary sample with an explicit condition on _time. Any other difference per field means the bucket, the filter or the access context is wrong.
The decision for each case #
Your server is InfluxDB Cloud or OSS 2.4 or later, and you must keep InfluxQL scripts now. Use the 1.x /query endpoint: migrate or confirm the data in buckets, build the database-to-bucket mapping, and point the script at the endpoint with a token that can read the mapped bucket. Plan the Flux rewrite anyway; the endpoint is a compatibility layer, not a destination.
Your server is an OSS build before 2.4. Rewrite to Flux. On those releases Flux is the documented query path — there is no documented compatibility endpoint to fall back on, and no CLI flag revives the 1.8 grammar. The pipeline above is the full rewrite of the win_cpu mean query; extend it the same way for the other InfluxQL calls in the batch, one stage at a time.
Either way, verify before you trust the numbers. Confirm the executable is the 2.x binary and the bucket holds the migrated data under the job's own token. Test range() and filter() before mean(). Compare means per field and tag set against a controlled 1.8 window, not by total row count. And replace every typographic quote in the batch with ASCII quotes so the next failure, when there is one, is a query failure you can read.
Questions asked
Does the -execute option exist at all in the 2.x command-line tool?
No. The 2.x tool has no 1.8 option grammar; its query operation accepts Flux text, and the target bucket is named inside the query itself. A 1.8 line that opens with the -execute option fails at the option parser before the query language is even considered, so no flag combination runs the old batch unchanged against a 2.x CLI.
What must be in place before the /query endpoint returns data?
Three things. The 1.x data must have been migrated into buckets on the 2.x server. The old database name and retention policy must be mapped to that bucket, because the endpoint addresses data by the 1.x names. And the caller must authenticate with a token that can read the mapped bucket under the 2.x authorization model.
Why does mean() return a different number of rows than the old mean(*)?
InfluxQL collapses the selected fields into columns of one result, while Flux groups input points into separate tables by field and tag set and averages each table into a single _value. So the two calls produce different shapes by design. Compare one field and tag set at a time against a verified 1.x reference window; a total row count proves nothing.
Can the Flux query use the same start and end values the batch already passes?
Yes, as RFC3339 timestamps such as 2022-08-01T12:00:00Z. Keep the batch substitution and the Flux quoting as separate layers: print the fully rendered query text first, then submit that exact text. That isolates a malformed Flux line from a batch variable that never expanded.
