Skip to main content
Version: latest

Install

This section shows an example of installing CnosDB using Docker. This is the simplest way to start CnosDB.

tip

For other installation methods, please see Installing CnosDB

Docker install

  1. Installing a Docker environment

  2. Start the container with Docker

  docker run --name cnosdb -p 8902:8902 -d cnosdb/cnosdb:community-latest
  1. Enter the container
  docker exec -it cnosdb sh
  1. Run cnosdb-cli
  cnosdb-cli --port 8902

It will display the following:

CnosDB CLI v2.3.0
Input arguments: Args { host: "localhost", port: 8902, user: "cnosdb", password: None, database: "public", target_partitions: Some(1), data_path: None, file: [], rc: None, format: Table, quiet: false }
public ❯

Download Sample Data

If in cnosdb-cli, type \q to exit

Executing the following command in the shell will generate a data file locally in Line Protocol format with the name oceanic_station

curl -o oceanic_station.txt https://dl.cnosdb.com/sample/oceanic_station.txt

Import data

  • Start the CLI

    cnosdb-cli
  • Create the database

    create database oceanic_station with ttl '10000d';
  • Switch to the specified database

    \c oceanic_station
  • Import data

    Execute the \w command, followed by the absolute path of the data file or the working path relative to cnosdb-cli.

    \w oceanic_station.txt

Data Query

  • View all tables

    SHOW TABLES;

    Successful execution returns the following results:

    +-------+
    | Table |
    +-------+
    | sea |
    | wind |
    | air |
    +-------+
    Query took 0.002 seconds.
  • Query data

    SELECT * FROM air limit 10;

    Successful execution returns the following results:

    +---------------------+------------+------------+-------------+----------+
    | time | station | visibility | temperature | pressure |
    +---------------------+------------+------------+-------------+----------+
    | 2022-01-14 16:00:00 | XiaoMaiDao | 50 | 63 | 52 |
    | 2022-01-14 16:03:00 | XiaoMaiDao | 56 | 62 | 54 |
    | 2022-01-14 16:06:00 | XiaoMaiDao | 58 | 75 | 57 |
    | 2022-01-14 16:09:00 | XiaoMaiDao | 65 | 76 | 50 |
    | 2022-01-14 16:12:00 | XiaoMaiDao | 79 | 57 | 60 |
    | 2022-01-14 16:15:00 | XiaoMaiDao | 71 | 68 | 51 |
    | 2022-01-14 16:18:00 | XiaoMaiDao | 66 | 55 | 50 |
    | 2022-01-14 16:21:00 | XiaoMaiDao | 64 | 78 | 77 |
    | 2022-01-14 16:24:00 | XiaoMaiDao | 63 | 50 | 52 |
    | 2022-01-14 16:27:00 | XiaoMaiDao | 72 | 69 | 56 |
    +---------------------+------------+------------+-------------+----------+
    Query took 0.635 seconds.

For more information about database operations, please refer to:

SQL

Programming Interface