All Products
Search
Document Center

Time Series Database:CLI of TSDB for InfluxDB®

Last Updated:Mar 28, 2026

The influx command-line interface (CLI) provides an interactive shell for the TSDB for InfluxDB® HTTP API. Use it to write data manually, import data from files, run InfluxQL or Flux queries, and view results in multiple formats.

Download the CLI

Download the binary package for your operating system:

Extract the archive. The influx binary is in the extracted folder. On Windows, the file is named influx.exe.

Connect to an instance

All connections to TSDB for InfluxDB® require SSL. Pass the five required flags every time you start the CLI:

$ ./influx -ssl -username "myname" -password "mypassword" -host ts-xxxxxx.influxdata.rds.aliyuncs.com -port 3242
Connected to https://<Endpoint>:3242 version 1.8.x
InfluxDB shell version: 1.8.x

Required flags

FlagDescription
-sslConnect to the server over HTTPS.
-usernameUsername for the instance.
-passwordPassword for the instance.
-hostEndpoint of the instance. Replace ts-xxxxxx with your instance ID.
-portPort number. Use 8086 for virtual private cloud (VPC) connections and 3242 for Internet connections.

After connecting, run InfluxQL statements and CLI commands directly in your terminal. To run Flux statements instead, set -type flux when starting the CLI. Run help inside the shell to list available commands. To stop a long-running query, press Ctrl+C.

Environment variables

The influx CLI supports the following environment variables. Both uppercase and lowercase are accepted; uppercase takes precedence.

VariableDescriptionFormatExample
HTTP_PROXYProxy server for HTTP connections.[protocol://][:port]HTTP_PROXY=http://localhost:1234
HTTPS_PROXYProxy server for HTTPS connections. Takes precedence over HTTP_PROXY when both are set.[protocol://][:port]HTTPS_PROXY=https://localhost:1443
NO_PROXYComma-separated list of hosts that bypass the proxy. Set to * to bypass all hosts.Comma-separated hostsNO_PROXY=123.45.67.89,123.45.67.90
INFLUX_USERNAMEUsername for the CLI (alternative to -username).
INFLUX_PASSWORDPassword for the CLI (alternative to -password).

influx flags

Pass flags when starting influx. Run $ influx --help to see all available flags.

FlagDescription
-compressedTreat the import file as compressed. Must be used with -import.
-database 'database name'Database to connect to.
-execute '<command>'Run an InfluxQL command and exit.
-format 'json|csv|column'Format of server responses. Default: column.
-host '<hostname>'Host to connect to.
-importImport data from a file.
-password '<password>'Password. If omitted, the CLI prompts for it. Alternatively, set INFLUX_PASSWORD.
-pathPath to the import file. Must be used with -import.
-port 'port #'Port to connect to. Default: 3242.
-ppsMaximum data points per second during import. Default: 0 (no limit). Must be used with -import.
-precision 'rfc3339|h|m|s|ms|u|ns'Timestamp format and precision for queries and writes. Default: ns.
-prettyEnable pretty-printed JSON output.
-sslUse HTTPS for requests.
-typeInteractive shell type: influxql (default) or flux for the Flux Read-Eval-Print Loop (REPL).
-username 'username'Username. Alternatively, set INFLUX_USERNAME.
-versionDisplay the version and exit.

Run a command and exit with -execute

Use -execute to run a single InfluxQL command without entering the interactive shell.

Run a query that doesn't require a database:

$ influx -ssl -username <Username> -password <Password> -host <Endpoint> -port 3242 -execute 'SHOW DATABASES'
name: databases
---------------
name
NOAA_water_database
_internal
telegraf
pirates

Run a query against a specific database and change the timestamp precision:

$ influx -ssl -username <Username> -password <Password> -host <Endpoint> -port 3242 -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

Set response format with -format

The default format is column. The following examples show all three available formats.

column (default):

$ influx -ssl -username <Username> -password <Password> -host <Endpoint> -port 3242 -format=column
[...]
> SHOW DATABASES
name: databases
---------------
name
NOAA_water_database
_internal
telegraf
pirates

csv:

$ influx -ssl -username <Username> -password <Password> -host <Endpoint> -port 3242 -format=csv
[...]
> SHOW DATABASES
name,name
databases,NOAA_water_database
databases,_internal
databases,telegraf
databases,pirates

json:

$ influx -ssl -username <Username> -password <Password> -host <Endpoint> -port 3242 -format=json
[...]
> SHOW DATABASES
{"results":[{"series":[{"name":"databases","columns":["name"],"values":[["NOAA_water_database"],["_internal"],["telegraf"],["pirates"]]}]}]}

json with `-pretty`:

$ influx -ssl -username <Username> -password <Password> -host <Endpoint> -port 3242 -format=json -pretty
[...]
> SHOW DATABASES
{
    "results": [
        {
            "series": [
                {
                    "name": "databases",
                    "columns": [
                        "name"
                    ],
                    "values": [
                        [
                            "NOAA_water_database"
                        ],
                        [
                            "_internal"
                        ],
                        [
                            "telegraf"
                        ],
                        [
                            "pirates"
                        ]
                    ]
                }
            ]
        }
    ]
}

Import data from a file with -import

Use -import to load data from a file into TSDB for InfluxDB®.

An import file has two sections:

  • DDL (Data Definition Language) (optional): InfluxQL commands to create the target database and retention policy. Skip this section if the database and retention policy already exist.

  • DML (Data Manipulation Language): Context metadata specifying the target database and retention policy, followed by data in line protocol format.

Example

Suppose that a database named pirates and a retention policy named oneday are created.

File datarrr.txt:

# DML
# CONTEXT-DATABASE: pirates
# CONTEXT-RETENTION-POLICY: oneday
treasures,captain_id=dread_pirate_roberts value=801 1439856000
treasures,captain_id=flint value=29 1439856000
treasures,captain_id=sparrow value=38 1439856000
treasures,captain_id=tetra value=47 1439856000
treasures,captain_id=crunch value=109 1439858880

Command:

$influx -ssl -username <Username> -password <Password> -host <Endpoint> -port 3242 -import -path=datarrr.txt -precision=s

Output:

2015/12/22 12:25:06 Processed 0 commands
2015/12/22 12:25:06 Processed 5 inserts
2015/12/22 12:25:06 Failed 0 inserts

Usage notes for `-import`

  • Include timestamps in every data point. Without timestamps, TSDB for InfluxDB® assigns the same timestamp to all points in the batch, which can cause unintended data overwrites.

  • To limit the import rate, use -pps to set the maximum number of data points per second. The default is 0 (no limit).

  • To import a .gz compressed file, add the -compressed flag.

  • For files with more than 5,000 data points, split the file into smaller batches of 5,000 to 10,000 points. Smaller batches increase the number of HTTP requests and can reduce performance. Each HTTP request has a five-second timeout; if a request times out, TSDB for InfluxDB® retries writing the points, but the write may not succeed.

influx commands

Run help inside the shell to list available commands. The following table describes each command.

CommandDescription
authPrompts for username and password. Alternatively, set INFLUX_USERNAME and INFLUX_PASSWORD as environment variables.
chunkedEnables chunked responses from the server. Enabled by default.
chunk size <size>Sets the chunk size for responses. Default: 10,000. Set to 0 to reset to the default.
clear [database | db | retention policy | rp]Clears the current database or retention policy context.
connect <host:port>Connects to a different server without exiting the shell. Default: localhost:8086.
consistency <level>Sets the write consistency level. Valid values: any, one, quorum, all.
Ctrl+CTerminates a running query. Useful for stopping long-running queries that return large result sets.
exit | quit | Ctrl+DExits the influx shell.
format <format>Sets the server response format. Valid values: json, csv, column.
historyDisplays command history. Use the up arrow to re-run a previous command. The CLI stores the latest 1,000 commands in .influx_history in your home directory.
insertWrites data using line protocol.
precision <format>Sets the timestamp format and precision. Same values as the -precision flag. Default: ns.
prettyEnables pretty-printed JSON output.
settingsDisplays current shell settings: Host, Username, Database, Retention Policy, Pretty, Chunked, Chunk Size, Format, and Write Consistency.
use ["<db>" | "<db>"."<rp>"]Sets the current database and/or retention policy. If no retention policy is specified, the DEFAULT retention policy is used.

Write data with insert

Use insert to write data in line protocol format. To write to a specific retention policy, use insert into <retention policy> <line protocol>.

Write to the default (DEFAULT) retention policy:

> INSERT treasures,captain_id=pirate_king value=2
>

Write to the oneday retention policy:

> INSERT INTO oneday treasures,captain_id=pirate_king value=2
Using retention policy oneday
>

Run InfluxQL queries

All InfluxQL queries are supported in the influx shell. For details, see Overview of data exploration, Schema exploration, and Database management.