自学内容网 自学内容网

第二章:快速体验 TDengine

快速体验 TDengine

目标

  • 掌握tdengine写入与查询

步骤

步骤 1: 连接到 TDengine

首先,确保 TDengine 容器正在运行。您可以使用以下命令连接到 TDengine 的命令行工具:

[root@master105 docker-tdengine]# docker exec -it  1e2331476ee2 taos
Welcome to the TDengine Command Line Interface, Client Version:3.3.2.0
Copyright (c) 2023 by TDengine, all rights reserved.


  *********************************  Tab Completion  *************************************
  *   The TDengine CLI supports tab completion for a variety of items,                   *
  *   including database names, table names, function names and keywords.                *
  *   The full list of shortcut keys is as follows:                                      *
  *    [ TAB ]        ......  complete the current word                                  *
  *                   ......  if used on a blank line, display all supported commands    *
  *    [ Ctrl + A ]   ......  move cursor to the st[A]rt of the line                     *
  *    [ Ctrl + E ]   ......  move cursor to the [E]nd of the line                       *
  *    [ Ctrl + W ]   ......  move cursor to the middle of the line                      *
  *    [ Ctrl + L ]   ......  clear the entire screen                                    *
  *    [ Ctrl + K ]   ......  clear the screen after the cursor                          *
  *    [ Ctrl + U ]   ......  clear the screen before the cursor                         *
  ****************************************************************************************

Server is TDengine Community Edition, ver:3.3.2.0 and will never expire.

taos>

步骤 2: 创建数据库和表

在 TDengine 的命令行工具中,执行以下 SQL 语句来创建数据库和表:

taos> CREATE DATABASE weather;
Create OK, 0 row(s) affected (0.477529s)

taos> USE weather;
Database changed.

taos>
taos> CREATE TABLE temperature (
    >     ts TIMESTAMP,
    >     location BINARY(20),
    >     temperature FLOAT
    > );
Create OK, 0 row(s) affected (0.004864s)

步骤 3: 插入数据

插入一些示例数据:


taos> INSERT INTO temperature VALUES ('2023-10-01 00:00:00', 'Beijing', 25.0);
Insert OK, 1 row(s) affected (0.001290s)

taos> INSERT INTO temperature VALUES ('2023-10-01 01:00:00', 'Shanghai', 27.5);
Insert OK, 1 row(s) affected (0.000572s)

taos> INSERT INTO temperature VALUES ('2023-10-01 02:00:00', 'Guangzhou', 30.0);
Insert OK, 1 row(s) affected (0.000722s)

taos> INSERT INTO temperature VALUES ('2023-10-01 03:00:00', 'Beijing', 24.5);
Insert OK, 1 row(s) affected (0.002174s)

步骤 4: 查询数据

查询刚刚插入的数据:

taos> SELECT * FROM temperature;
           ts            |        location        |     temperature      |
==========================================================================
 2023-10-01 00:00:00.000 | Beijing                |           25.0000000 |
 2023-10-01 01:00:00.000 | Shanghai               |           27.5000000 |
 2023-10-01 02:00:00.000 | Guangzhou              |           30.0000000 |
 2023-10-01 03:00:00.000 | Beijing                |           24.5000000 |
Query OK, 4 row(s) in set (0.005201s)

感谢阅读!如果你喜欢这篇文章,不妨分享给你的朋友。想要获取更多技术资讯,可以关注我们的微信号:aldrichsea。我们在那里等你,一起探索技术的无限可能。


原文地址:https://blog.csdn.net/RodJohnsonDoctor/article/details/143508751

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!