InfluxDB OSS v1
This page documents an earlier version of InfluxDB OSS.InfluxDB 3 Core is the latest stable version.
With InfluxDB open source (OSS)installed, you’re ready to start working with time series data.This guide uses theinfluxcommand line interface (CLI), which is included with InfluxDBand provides direct access to the database.The CLI communicates with InfluxDB through the HTTP API on port8086.
Docker users: Access the CLI from your container using:
dockerexec -it <container-name> influxYou can also interact with InfluxDB using the HTTP API directly.SeeWriting Data andQuerying Data for examples usingcurl.
After installing InfluxDB locally, theinflux command is available from your terminal.Runninginflux starts the CLI and connects to your local InfluxDB instance(ensure InfluxDB is running withservice influxdb start orinfluxd).To start the CLI and connect to the local InfluxDB instance, run the following command.The-precision argument specifies the format and precision of any returned timestamps.
$ influx -precision rfc3339Connected to http://localhost:8086 version 1.12.2InfluxDB shell 1.12.2>Theinflux CLI connects to portlocalhost:8086 (the default).The timestamp precisionrfc3339 tells InfluxDB to return timestamps inRFC3339 format (YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ).
To view available options for customizing CLI connection parameters or other settings, runinflux --help in your terminal.
The command line is ready to take input in the form of the Influx Query Language (InfluxQL) statements.To exit the InfluxQL shell, typeexit and hit return.
A fresh install of InfluxDB has no databases (apart from the system_internal),so creating one is our first task.You can create a database with theCREATE DATABASE <db-name> InfluxQL statement,where<db-name> is the name of the database you wish to create.Names of databases can contain any unicode character as long as the string is double-quoted.Names can also be left unquoted if they containonly ASCII letters,digits, or underscores and do not begin with a digit.
Throughout this guide, we’ll use the database namemydb:
>CREATEDATABASEmydb>Note: After hitting enter, a new prompt appears and nothing else is displayed.In the CLI, this means the statement was executed and there were no errors to display.There will always be an error displayed if something went wrong.
Now that themydb database is created, we’ll use theSHOW DATABASES statementto display all existing databases:
>SHOWDATABASESname:databasesname----_internalmydb>Note: The
_internaldatabase is created and used by InfluxDB to store internal runtime metrics.Check it out later to get an interesting look at how InfluxDB is performing under the hood.
UnlikeSHOW DATABASES, most InfluxQL statements must operate against a specific database.You may explicitly name the database with each query,but the CLI provides a convenience statement,USE <db-name>,which will automatically set the database for all future requests. For example:
>USEmydbUsingdatabasemydb>Now future commands will only be run against themydb database.
Now that we have a database, InfluxDB is ready to accept queries and writes.
First, a short primer on the datastore.Data in InfluxDB is organized by “time series”,which contain a measured value, like “cpu_load” or “temperature”.Time series have zero to manypoints, one for each discrete sample of the metric.Points consist oftime (a timestamp), ameasurement (“cpu_load”, for example),at least one key-valuefield (the measured value itself, e.g.“value=0.64”, or “temperature=21.2”), and zero to many key-valuetags containing any metadata about the value (e.g.“host=server01”, “region=EMEA”, “dc=Frankfurt”).
Conceptually you can think of ameasurement as an SQL table,where the primary index is always time.tags andfields are effectively columns in the table.tags are indexed, andfields are not.The difference is that, with InfluxDB, you can have millions of measurements,you don’t have to define schemas up-front, and null values aren’t stored.
Points are written to InfluxDB using the InfluxDB line protocol, which follows the following format:
<measurement>[,<tag-key>=<tag-value>...] <field-key>=<field-value>[,<field2-key>=<field2-value>...] [unix-nano-timestamp]The following lines are all examples of points that can be written to InfluxDB:
cpu,host=serverA,region=us_west value=0.64payment,device=mobile,product=Notepad,method=credit billed=33,licenses=3i 1434067467100293230stock,symbol=AAPL bid=127.46,ask=127.48temperature,machine=unit42,type=assembly external=25,internal=37 1434067467000000000Note: For details on the InfluxDB line protocol, seeInfluxDB line protocol syntax page.
To insert a single time series data point into InfluxDB using the CLI, enterINSERT followed by a point:
>INSERTcpu,host=serverA,region=us_westvalue=0.64>A point with the measurement name ofcpu and tagshost andregion has now been written to the database, with the measuredvalue of0.64.
Now we will query for the data we just wrote:
>SELECT"host","region","value"FROM"cpu"name:cpu---------timehostregionvalue2015-10-21T19:28:07.580664347ZserverAus_west0.64>Note: We did not supply a timestamp when writing our point.When no timestamp is supplied for a point, InfluxDB assigns the local current timestamp when the point is ingested.That means your timestamp will be different.
Let’s try storing another type of data, with two fields in the same measurement:
>INSERTtemperature,machine=unit42,type=assemblyexternal=25,internal=37>To return all fields and tags with a query, you can use the* operator:
>SELECT*FROM"temperature"name:temperature-----------------timeexternalinternalmachinetype2015-10-21T19:28:08.385013942Z2537unit42assembly>Warning: Using* without aLIMIT clause on a large database can cause performance issues.You can useCtrl+C to cancel a query that is taking too long to respond.
InfluxQL has manyfeatures and keywords that are not covered here,including support for Go-style regex. For example:
>SELECT*FROM/.*/LIMIT1-->SELECT*FROM"cpu_load_short"-->SELECT*FROM"cpu_load_short"WHERE"value">0.9You can also interact with InfluxDB using HTTP requests with tools likecurl:
curl -G http://localhost:8086/query --data-urlencode"q=CREATE DATABASE mydb"curl -i -XPOST'http://localhost:8086/write?db=mydb'\ --data-binary'cpu,host=serverA,region=us_west value=0.64'curl -G'http://localhost:8086/query?pretty=true'\ --data-urlencode"db=mydb"\ --data-urlencode"q=SELECT * FROM cpu"This is all you need to know to write data into InfluxDB and query it back.To learn more about the InfluxDB write protocol,check out the guide onWriting Data.To further explore the query language,check out the guide onQuerying Data.For more information on InfluxDB concepts, check out theKey Concepts page.
Was this page helpful?
Thank you for your feedback!
Thank you for being part of our community!We welcome and encourage your feedback and bug reports for InfluxDB and this documentation.To find support, use the following resources:
Customers with an annual or support contract cancontact InfluxData Support.
Key enhancements in InfluxDB 3.7 and the InfluxDB 3 Explorer 1.5.
InfluxDB 3.7 is now available for both Core and Enterprise, landing alongsideversion 1.5 of the InfluxDB 3 Explorer UI. This release focuses on givingdevelopers faster visibility into what their system is doing with one-clickmonitoring, a streamlined installation pathway, and broader updates thatsimplify day-to-day operations.
For more information, check out:
latest tag for InfluxDB Docker images willpoint to InfluxDB 3 Core. To avoid unexpected upgrades, use specific versiontags in your Docker deployments.If using Docker to install and run InfluxDB, thelatest tag will point toInfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags inyour Docker deployments. For example, if using Docker to run InfluxDB v2,replace thelatest version tag with a specific version tag in your Dockerpull command–for example:
docker pull influxdb:2