Use the influxdb3 CLI to write data
Use the influxdb3
CLI
to write line protocol data to InfluxDB 3 Core.
Use the API for batching and higher-volume writes
The influxdb3
CLI lets you quickly get started writing data to InfluxDB 3 Core.
For batching and higher-volume write workloads, use
API client libraries
or Telegraf.
Construct line protocol
With a basic understanding of line protocol, you can construct data in line protocol format and write it to InfluxDB 3 Core. Consider a use case where you collect data from sensors in your home. Each sensor collects temperature, humidity, and carbon monoxide readings. To collect this data, use the following schema:
- table:
home
- tags
room
: Living Room or Kitchen
- fields
temp
: temperature in °C (float)hum
: percent humidity (float)co
: carbon monoxide in parts per million (integer)
- timestamp: Unix timestamp in second precision
- tags
The following line protocol represents the schema described above:
For this tutorial, you can either pass this line protocol directly to the
influxdb3 write
command as a string, via stdin
, or you can save it to and
read it from a file.
Write the line protocol to InfluxDB
Use the influxdb3 write
command
to write the home sensor sample data to InfluxDB 3 Core.
Provide the following:
The database name using the
--database
optionYour InfluxDB 3 Core authorization token using the
-t
,--token
optionLine protocol. Provide the line protocol in one of the following ways:
- a string
- a path to a file that contains the line protocol using the
--file
option - from stdin
InfluxDB 3 Core auto-detects the timestamp precision by identifying which precision results in timestamps relatively close to “now.”
In your terminal, enter the following command to create the sample data file:
echo 'home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000' > ./home.lp
Enter the following CLI command to write the data from the sample file:
influxdb3 write \ --database
DATABASE_NAME\ --tokenAUTH_TOKEN\ --file ./home.lp
In your terminal, enter the following command to create the sample data file:
echo 'home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000' > ./home.lp
Enter the following CLI command to write the data from the sample file:
cat ./home.lp | influxdb3 write \ --database
DATABASE_NAME\ --tokenAUTH_TOKEN
Replace the following:
DATABASE_NAME
: the name of the database to write toAUTH_TOKEN
: your InfluxDB 3 Core authorization tokenWhile in beta, InfluxDB 3 Core does not require an authorization token.
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB 3 Core and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.