Using influx - InfluxDB command line interface

This page documents an earlier version of InfluxDB OSS. InfluxDB 3 Core is the latest stable version.

The influx command line interface (CLI) provides an interactive shell for the HTTP API associated with influxd. Use influx to write data (manually or from a file), query data interactively, view query output in different formats, and manage resources in InfluxDB.

Launch influx

The influx CLI is included when you install InfluxDB OSS 1.13.

The influx CLI is installed at the following path, depending on your system and package manager:

/usr/bin/influx
/usr/local/bin/influx
/opt/homebrew/opt/influxdb@1/bin/influx

To access the CLI, first launch the influxd database process and then launch influx in your terminal.

influx

If successfully connected to an InfluxDB node, the output is the following:

Connected to http://localhost:8086 version 1.13.0
InfluxDB shell version: 1.13.0
>

The versions of InfluxDB and the CLI should be identical. If not, parsing issues can occur with queries.

In the prompt, you can enter InfluxQL queries as well as CLI-specific commands. Enter help to get a list of available commands. Use Ctrl+C to cancel if you want to cancel a long-running InfluxQL query.

Environment variables

The following environment variables can be used to configure settings used by the influx client. They can be specified in lower or upper case, however the upper case version takes precedence.

HTTP_PROXY

Defines the proxy server to use for HTTP.

Value format:[protocol://]<host>[:port]

HTTP_PROXY=http://localhost:1234

HTTPS_PROXY

Defines the proxy server to use for HTTPS. Takes precedence over HTTP_PROXY for HTTPS.

Value format:[protocol://]<host>[:port]

HTTPS_PROXY=https://localhost:1443

NO_PROXY

List of host names that should not go through any proxy. If set to an asterisk ‘*’ only, it matches all hosts.

Value format: comma-separated list of hosts

NO_PROXY=123.45.67.89,123.45.67.90

influx arguments

Arguments specify connection, write, import, and output options for the CLI session.

influx provides the following arguments:

-h, -help List influx arguments

-compressed Set to true if the import file is compressed. Use with -import.

-consistency 'any|one|quorum|all' Set the write consistency level.

-database 'database name' The database to which influx connects.

-execute 'command' Execute an InfluxQL command and quit. See -execute.

-format 'json|csv|column' Specifies the format of the server responses. See -format.

-host 'host name' The host to which influx connects. By default, InfluxDB runs on localhost.

-import

Import new data or exported data from a file.

See -import.

-password 'password' The password influx uses to connect to the server. influx will prompt for a password if you leave it blank (-password ''). Alternatively, set the password for the CLI with the INFLUX_PASSWORD environment variable.

-path The path to the file to import. Use with -import.

-port 'port #' The port to which influx connects. By default, InfluxDB runs on port 8086.

-pps How many points per second the import will allow. By default, pps is zero and influx will not throttle importing. Use with -import.

-precision 'rfc3339|h|m|s|ms|u|ns' Specifies the format/precision of the timestamp: rfc3339 (YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ), h (hours), m (minutes), s (seconds), ms (milliseconds), u (microseconds), ns (nanoseconds). Precision defaults to nanoseconds.

Setting the precision to rfc3339 (-precision rfc3339) works with the -execute option, but it does not work with the -import option. All other precision formats (e.g., h,m,s,ms,u, and ns) work with the -execute and -import options.

-pretty Turns on pretty print for the json format.

-ssl Use HTTPS for requests.

-unsafeSsl Disables SSL certificate verification. Use when connecting over HTTPS with a self-signed certificate.

-username 'username' The username that influx uses to connect to the server. Alternatively, set the username for the CLI with the INFLUX_USERNAME environment variable.

-version Display the InfluxDB version and exit.

The following sections provide detailed examples for some arguments, including -execute, -format, and -import.

Execute an InfluxQL command and quit with -execute

Execute queries that don’t require a database specification:

$ influx -execute 'SHOW DATABASES'
name: databases
---------------
name
NOAA_water_database
_internal
telegraf
pirates

Execute queries that do require a database specification, and change the timestamp precision:

$ influx -execute 'SELECT * FROM "h2o_feet" LIMIT 3' -database="NOAA_water_database" -precision=rfc3339
name: h2o_feet
--------------
time			               level description	    location	     water_level
2015-08-18T00:00:00Z	 below 3 feet		        santa_monica	 2.064
2015-08-18T00:00:00Z	 between 6 and 9 feet  coyote_creek  8.12
2015-08-18T00:06:00Z	 between 6 and 9 feet  coyote_creek  8.005

Specify the format of the server responses with -format

The default format is column:

$ influx -format=column
[...]
> SHOW DATABASES
name: databases
---------------
name
NOAA_water_database
_internal
telegraf
pirates

Change the format to csv:

$ influx -format=csv
[...]
> SHOW DATABASES
name,name
databases,NOAA_water_database
databases,_internal
databases,telegraf
databases,pirates

Change the format to json:

$ influx -format=json
[...]
> SHOW DATABASES
{"results":[{"series":[{"name":"databases","columns":["name"],"values":[["NOAA_water_database"],["_internal"],["telegraf"],["pirates"]]}]}]}

Change the format to json and turn on pretty print:

$ influx -format=json -pretty
[...]
> SHOW DATABASES
{
    "results": [
        {
            "series": [
                {
                    "name": "databases",
                    "columns": [
                        "name"
                    ],
                    "values": [
                        [
                            "NOAA_water_database"
                        ],
                        [
                            "_internal"
                        ],
                        [
                            "telegraf"
                        ],
                        [
                            "pirates"
                        ]
                    ]