文档文档

Use the InfluxQL shell (使用 InfluxQL Shell)

Use the InfluxQL interactive shell to execute InfluxQL queries with InfluxDB. (使用 InfluxQL 交互式 Shell 在 InfluxDB 中执行 InfluxQL 查询。)

Map database and retention policies to buckets (将数据库和保留策略映射到存储桶)

InfluxQL queries require a database and retention policy to query data. In InfluxDB 2.7, databases and retention policies have been combined and replaced with buckets. To use the InfluxQL to query an InfluxDB 2.7 bucket, first map your DBRP combinations to an appropriate bucket. (InfluxQL 查询需要数据库和保留策略才能查询数据。 在 InfluxDB 2.7 中,数据库和保留策略已合并并替换为 存储桶。 要使用 InfluxQL 查询 InfluxDB 2.7 存储桶,请首先将您的 DBRP 组合映射到适当的存储桶。)

For information about creating DBRP mappings, see Query data with InfluxQL. (有关创建 DBRP 映射的信息,请参阅 使用 InfluxQL 查询数据。)

Download and install the influx CLI (下载并安装 influx CLI)

The InfluxQL REPL is included in the influx CLI (2.4+). Download and install the influx CLI. (InfluxQL REPL 包含在 influx CLI (2.4+) 中。 下载并安装 influx CLI。)

Start the InfluxQL shell (启动 InfluxQL Shell)

Use the influx v1 shell command to start an InfluxQL shell session. (使用 influx v1 shell 命令 启动 InfluxQL shell 会话。)

influx v1 shell

Configure your InfluxDB connection (配置您的 InfluxDB 连接)

The influx v1 shell command requires the following to connect to InfluxDB (influx v1 shell 命令需要以下信息才能连接到 InfluxDB)

Use one of the following methods to provide these credentials to the influx v1 shell command (使用以下方法之一将这些凭据提供给 influx v1 shell 命令)

The influx CLI lets your configure and store multiple sets of connection credentials to use with commands. Each set of credentials is a CLI config. Use CLI configs to provide required credentials to the influx v1 shell command. (influx CLI 允许您配置和存储多组连接凭据以用于命令。 每组凭据都是一个 CLI 配置。 使用 CLI 配置为 influx v1 shell 命令提供所需的凭据。)

  1. Create a new CLI config and set it to active. (创建一个新的 CLI 配置并将其设置为激活。)

    influx config create --config-name <config-name> \
      --host-url https://127.0.0.1:8086 \
      --org example-org \
      --token mY5up3Rs3CrE7t0k3N \
      --active
    
  2. Start an InfluxQL shell (启动 InfluxQL Shell)

    influx v1 shell
    

All influx commands use credentials provided by the active CLI config. For more information about managing CLI configs, see the influx config documentation. (所有 influx 命令都使用活动 CLI 配置提供的凭据。 有关管理 CLI 配置的更多信息,请参阅 influx config 文档。)

Use influx v1 shell command flags to provide the required credentials (使用 influx v1 shell 命令标志提供所需的凭据)

influx v1 shell \
  --host https://127.0.0.1:8086 \
  --org example-org \
  --token mY5up3Rs3CrE7t0k3N

Use environment variables to provided the required credentials. The influx CLI will automatically use the following environment variables for required credentials if the environment variables are set (使用环境变量提供所需的凭据。 如果设置了环境变量,influx CLI 将自动使用以下环境变量获取所需的凭据)

  • INFLUX_HOST
  • INFLUX_ORG or INFLUX_ORG_ID
  • INFLUX_TOKEN
export INFLUX_HOST=https://127.0.0.1:8086
export INFLUX_ORG=example-org
export INFLUX_TOKEN=mY5up3Rs3CrE7t0k3N

influx v1 shell

Execute InfluxQL queries (执行 InfluxQL 查询)

Within the InfluxQL shell, execute any InfluxQL query supported by InfluxDB 2.7. For information about what queries are supported see InfluxQL support in InfluxDB 2.7. (在 InfluxQL shell 中,执行 InfluxDB 2.7 支持的任何 InfluxQL 查询。 有关支持哪些查询的信息,请参阅 InfluxDB 2.7 中的 InfluxQL 支持。)

View the InfluxQL documentation (1.11) for in-depth documentation about the query language. (查看 InfluxQL 文档 (1.11),获取有关查询语言的深入文档。)

Use and configure display formats (使用和配置显示格式)

The InfluxQL shell outputs query results using different display formats. Use the format helper command to specify which display format to use. (InfluxQL shell 使用不同的显示格式输出查询结果。 使用 format 辅助命令 来指定要使用的显示格式。)

The InfluxQL shell uses the table display format by default. If using another display format and you want to switch back to the table format, run the following in the InfluxQL shell. (InfluxQL shell 默认使用 table 显示格式。 如果使用其他显示格式并且想要切换回 table 格式,请在 InfluxQL shell 中运行以下命令。)

format table

Table-formatted results (表格格式化结果)

The table format outputs results in an interactive table format. (表格格式以交互式表格格式输出结果。)

InfluxQL shell table display format

Results are paginated. Use shift + up/down arrow to navigate between pages. Use q to exit out of the interactive table display. (结果是分页的。 使用 shift + up/down arrow 在页面之间导航。 使用 q 退出交互式表格显示。)

Configure the table display format (配置表格显示格式)

Use scientific notation (使用科学计数法)

To display values using scientific notation, use the scientific helper command to toggle scientific notation. (要使用科学计数法显示值,请使用 scientific 辅助命令 来切换科学计数法。)

Specify timestamp precision or format (指定时间戳精度或格式)

To specify the precision or format of timestamps returned in results, use the precision helper command. (要指定结果中返回的时间戳的精度或格式,请使用 precision 辅助命令。)

-- Return results formatted as RFC3339 timestamps
precision rfc3339

-- Return results with second-precision unix timestamps
precision s

To use the column format, run the following in the InfluxQL shell. (要使用 column 格式,请在 InfluxQL shell 中运行以下命令。)

format column

Column-formatted results (列格式化结果)

The column format displays results in a text-based column format. (column 格式以基于文本的列格式显示结果。)

name: cpu
time            usage_user          usage_system
----            ----------          ------------
1.62767581e+09  5.476026754935672   2.5629805588360313
1.62767581e+09  0.4999999999972715  0.09999999999990905
1.62767581e+09  18.718718718689555  10.810810810692704
1.62767581e+09  6.500000000090222   3.2000000000343425
1.62767581e+09  4.1999999999336435  1.3999999999778812
1.62767581e+09  7.992007992122577   4.095904095946467
1.62767581e+09  0.3000000000054934  0.1000000000010732

Configure the column display format (配置列显示格式)

Specify timestamp precision (指定时间戳精度)

To specify the precision or format of timestamps returned in results, use the precision helper command. (要指定结果中返回的时间戳的精度或格式,请使用 precision 辅助命令。)

-- Return results formatted as RFC3339 timestamps
precision rfc3339

-- Return results with second-precision unix timestamps
precision s

To use the csv format, run the following in the InfluxQL shell. (要使用 csv 格式,请在 InfluxQL shell 中运行以下命令。)

format csv

CSV-formatted results (CSV 格式化结果)

The csv format displays results in CSV format. (csv 格式以 CSV 格式显示结果。)

name,time,usage_user,usage_system
cpu,1.62767582e+09,4.207038819798416,3.5194098893833914
cpu,1.62767582e+09,0.19980019980215585,0.19980019980215585
cpu,1.62767582e+09,14.914914914981258,14.114114114162232
cpu,1.62767582e+09,5.805805805828698,4.004004003985887
cpu,1.62767582e+09,2.5025025025339978,1.8018018018273916
cpu,1.62767582e+09,7.299999999874271,5.699999999930733
cpu,1.62767582e+09,0.09999999999647116,0.0999999999987449

Configure the CSV display format (配置 CSV 显示格式)

Specify timestamp precision (指定时间戳精度)

To specify the precision or format of timestamps returned in results, use the precision helper command. (要指定结果中返回的时间戳的精度或格式,请使用 precision 辅助命令。)

-- Return results formatted as RFC3339 timestamps
precision rfc3339

-- Return results with second-precision unix timestamps
precision s

To use the json format, run the following in the InfluxQL shell. (要使用 json 格式,请在 InfluxQL shell 中运行以下命令。)

format json

JSON-formatted results (JSON 格式化结果)

The csv format displays results in JSON format. (csv 格式以 JSON 格式显示结果。)

{
    "results": [
        {
            "series": [
                {
                    "columns": [
                        "time",
                        "usage_user",
                        "usage_system"
                    ],
                    "name": "cpu",
                    "values": [
                        [
                            1627675850,
                            4.601935685334947,
                            4.139868872973054
                        ],
                        [
                            1627675850,
                            0.3992015968099201,
                            0.2994011976074401
                        ],
                        [
                            1627675850,
                            7.599999999947613,
                            7.299999999995634
                        ],
                        [
                            1627675850,
                            0.3992015968098205,
                            0.4990019960088718
                        ],
                        [
                            1627675850,
                            9.59040959050348,
                            8.49150849158481
                        ],
                        [
                            1627675850,
                            0.2997002996974768,
                            0.39960039959966437
                        ],
                        [
                            1627675850,
                            9.590409590464631,
                            8.691308691326773
                        ]
                    ]
                }
            ],
            "statement_id": 0
        }
    ]
}

配置 JSON 显示格式

美化 JSON 输出

默认情况下,json 显示格式返回未经格式化的 JSON 字符串。 要格式化 JSON,请使用 pretty 辅助命令切换 JSON 美化打印。

Specify timestamp precision (指定时间戳精度)

To specify the precision or format of timestamps returned in results, use the precision helper command. (要指定结果中返回的时间戳的精度或格式,请使用 precision 辅助命令。)

-- Return results formatted as RFC3339 timestamps
precision rfc3339

-- Return results with second-precision unix timestamps
precision s

InfluxQL shell helper commands (InfluxQL Shell 辅助命令)

InfluxQL shell 支持以下辅助命令

clear

清除基于会话的设置,例如数据库。

exit

退出 InfluxQL shell。

format

指定数据显示格式。 InfluxQL 支持以下显示格式

  • csv
  • json
  • column
  • table (默认)
-- Display query output using column display
format column

有关更多信息,请参阅 使用和配置显示格式

gopher

打印 Go gopher。

help

打印 InfluxQL shell 帮助选项。

history

查看 InfluxQL shell 历史记录。

precision

指定时间戳的格式或精度。 使用以下选项之一

  • rfc3339
  • h
  • m
  • s
  • ms
  • u
  • ns (默认)
-- Set timestamp precision to seconds
precision s

pretty

json 显示格式切换“美化打印”。

quit

退出 InfluxQL shell

scientific

table 显示格式切换科学计数法数字格式。

use

设置数据库和保留策略(可选),用于查询。

-- Use the exampledb database
use exampledb

-- Use the exampledb database and examplerp retention policy
use exampledb.examplerp

此页面是否对您有帮助?

感谢您的反馈!


Flux 的未来

Flux 即将进入维护模式。您可以继续像目前一样使用它,而无需对您的代码进行任何更改。

了解更多

InfluxDB 3 开源版本现已进入公开 Alpha 阶段

InfluxDB 3 开源版本现已可用于 Alpha 测试,并采用 MIT 或 Apache 2 许可。

我们正在发布两个产品作为 alpha 的一部分。

InfluxDB 3 Core 是我们新的开源产品。 它是一个用于时序和事件数据的最新数据引擎。 InfluxDB 3 Enterprise 是一个商业版本,它建立在 Core 的基础上,增加了历史查询功能、读取副本、高可用性、可扩展性和细粒度的安全性。

有关如何入门的更多信息,请查看