Documentation

influx write

The influx write command writes data to InfluxDB via stdin or from a specified file. Write data using line protocol, annotated CSV, or extended annotated CSV. If you write CSV data, CSV annotations determine how the data translates into line protocol.

Usage

influx write [flags]
influx write [command]

Required data

To write data to InfluxDB, you must provide the following for each row:

  • measurement
  • field
  • value

Line protocol

In line protocol, the structure of the line data determines the measurement, field, and value.

Annotated CSV

In annotated CSV, measurements, fields, and values are represented by the _measurement, _field, and _value columns. Their types are determined by CSV annotations. To successfully write annotated CSV to InfluxDB, include all annotation rows.

Extended annotated CSV

In extended annotated CSV, measurements, fields, and values and their types are determined by CSV annotations.

Subcommands

SubcommandDescription
dryrunWrite to stdout instead of InfluxDB

Flags

FlagDescriptionInput typeMaps to ?
-c--active-configCLI configuration to use for commandstring
-b--bucketBucket name (mutually exclusive with --bucket-id)stringINFLUX_BUCKET_NAME
--bucket-idBucket ID (mutually exclusive with --bucket)stringINFLUX_BUCKET_ID
--configs-pathPath to influx CLI configurations (default ~/.influxdbv2/configs)stringINFLUX_CONFIGS_PATH
--compressionInput compression (none or gzip, default is none unless input file ends with .gz.)string
--debugOutput errors to stderr
--encodingCharacter encoding of input (default UTF-8)string
--errors-filePath to a file used for recording rejected row errorsstring
-f--fileFile to importstringArray
--formatInput format (lp or csv, default lp)string
--headerPrepend header line to CSV input datastring
-h--helpHelp for the write command
--hostHTTP address of InfluxDB (default http://localhost:8086)stringINFLUX_HOST
--max-line-lengthMaximum number of bytes that can be read for a single line (default 16000000)integer
-o--orgOrganization name (mutually exclusive with --org-id)stringINFLUX_ORG
--org-idOrganization ID (mutually exclusive with --org)stringINFLUX_ORG_ID
-p--precisionPrecision of the timestamps (default ns)stringINFLUX_PRECISION
--rate-limitThrottle write rate (examples: 5MB/5min or 1MB/s).string
--skip-verifySkip TLS certificate verificationINFLUX_SKIP_VERIFY
--skipHeaderSkip first n rows of input datainteger
--skipRowOnErrorOutput CSV errors to stderr, but continue processing
-t--tokenAPI tokenstringINFLUX_TOKEN
-u--urlURL to import data fromstringArray

Examples

Authentication credentials

The examples below assume your InfluxDB host, organization, and token are provided by either the active influx CLI configuration or by environment variables (INFLUX_HOST, INFLUX_ORG, and INFLUX_TOKEN). If you do not have a CLI configuration set up or the environment variables set, include these required credentials for each command with the following flags:

  • --host: InfluxDB host
  • -o, --org or --org-id: InfluxDB organization name or ID
  • -t, --token: InfluxDB API token
Write line protocol
Write CSV data

Line protocol

Write line protocol via stdin
influx write --bucket example-bucket "
m,host=host1 field1=1.2,field2=5i 1640995200000000000
m,host=host2 field1=2.4,field2=3i 1640995200000000000
"
Write line protocol from a file
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol.txt
Write line protocol from multiple files
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol-1.txt \
  --file path/to/line-protocol-2.txt
Write line protocol from a URL
influx write \
  --bucket example-bucket \
  --url https://example.com/line-protocol.txt
Write line protocol from multiple URLs
influx write \
  --bucket example-bucket \
  --url https://example.com/line-protocol-1.txt \
  --url https://example.com/line-protocol-2.txt
Write line protocol from multiple sources
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol-1.txt \
  --url https://example.com/line-protocol-2.txt
Write line protocol from a compressed file
# The influx CLI assumes files with the .gz extension use gzip compression 
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol.txt.gz

# Specify gzip compression for gzipped files without the .gz extension
influx write \
  --bucket example-bucket \
  --file path/to/line-protocol.txt.comp \
  --compression gzip

CSV

Write annotated CSV data via stdin
influx write \
  --bucket example-bucket \
  --format csv \
  "#group,false,false,false,false,true,true
#datatype,string,long,dateTime:RFC3339,double,string,string
#default,_result,,,,,
,result,table,_time,_value,_field,_measurement
,,0,2020-12-18T18:16:11Z,72.7,temp,sensorData
,,0,2020-12-18T18:16:21Z,73.8,temp,sensorData
,,0,2020-12-18T18:16:31Z,72.7,temp,sensorData
,,0,2020-12-18T18:16:41Z,72.8,temp,sensorData
,,0,2020-12-18T18:16:51Z,73.1,temp,sensorData
"
Write extended annotated CSV data via stdin
influx write \
  --bucket example-bucket \
  --format csv \
  "#constant measurement,sensorData
#datatype dateTime:RFC3339,double
time,temperature
2020-12-18T18:16:11Z,72.7
2020-12-18T18:16:21Z,73.8
2020-12-18T18:16:31Z,72.7
2020-12-18T18:16:41Z,72.8
2020-12-18T18:16:51Z,73.1
"
Write annotated CSV data from a file
influx write \
  --bucket example-bucket \
  --file path/to/data.csv
Write annotated CSV data from multiple files
influx write \
  --bucket example-bucket \
  --file path/to/data-1.csv \
  --file path/to/data-2.csv
Write annotated CSV data from a URL
influx write \
  --bucket example-bucket \
  --url https://example.com/data.csv
Write annotated CSV data from multiple URLs
influx write \
  --bucket example-bucket \
  --url https://example.com/data-1.csv \
  --url https://example.com/data-2.csv
Write annotated CSV data from multiple sources
influx write \
  --bucket example-bucket \
  --file path/to/data-1.csv \
  --url https://example.com/data-2.csv
Prepend CSV data with annotation headers
influx write \
  --bucket example-bucket \
  --header "#constant measurement,birds" \
  --header "#datatype dateTime:2006-01-02,long,tag" \
  --file path/to/data.csv
Write annotated CSV data from a compressed file
# The influx CLI assumes files with the .gz extension use gzip compression 
influx write \
  --bucket example-bucket \
  --file path/to/data.csv.gz

# Specify gzip compression for gzipped files without the .gz extension
influx write \
  --bucket example-bucket \
  --file path/to/data.csv.comp \
  --compression gzip
Write annotated CSV data using rate limiting
influx write \
  --bucket example-bucket \
  --file path/to/data.csv \
  --rate-limit 5MB/5min

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.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following: