Databases 6 min read

Mastering TDengine: Essential Commands and Tips for IoT Time-Series Data

This guide walks you through TDengine setup for IoT, covering password changes, login syntax, database and table creation, super‑table design, tag management, and practical insertion examples, all with clear command‑line snippets.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Mastering TDengine: Essential Commands and Tips for IoT Time-Series Data

1. Change User Password

The default password for the root user is taosdata. Change it with:

alter user root pass 'your_password';

2. Login to the Database

Connect using the taos client. Parameters must be concatenated without spaces:

taos -uroot -p123456;

3. Database Operations

Create, select, and drop databases, and adjust their properties:

create database if not exists mydb keep 365 days 10 blocks 4;
use mydb;
drop database mydb;
drop database if exists mydb;
show databases;
alter database mydb comp 2;
alter database mydb replica 2;
alter database mydb keep 365;
alter database mydb quorum 2;
alter database mydb blocks 100;

4. Table Operations

Create regular tables, sub‑tables, and manage columns:

create table if not exists mytable (column_name timestamp, column_name int, ...);
create table table_name using super_table tags (column_value, column_value, ...);
drop table if exists mytable;
show tables;
show tables like "%table_name%";
describe mytable;
alter table mytable add column addfield int;
alter table mytable drop column addfield;

5. Super Table Operations

Super tables store common fields while tags hold device‑specific metadata:

create table if not exists mysupertable (time timestamp, column_name int, ...) tags (column_name nchar(50), column_name nchar(100), ...);
drop table if exists super_table;
show stables like "%super%";
describe super_table;
alter table super_table add column column_name int;
alter table super_table drop column column_name;
alter table super_table add tag column nchar(60);
alter table super_table drop tag tag_name;
alter table super_table change tag old_tag_name new_tag_name;
alter table item_table_name set tag column_key = "value";

6. Relationship Explanation

In an IoT scenario, each electric‑meter device can be represented as a sub‑table of a super table. The measurement fields (current, voltage) are regular columns, while owner name, location, and room number are stored as tags.

7. Practical Example

Creating a super table for electric meters and corresponding sub‑tables:

create database mydb;
use mydb;
create table super_dianbiao (ts timestamp, dianya float, dianliu float) tags (yezhu_name nchar(15), xiaoqu_location nchar(50), menpai_num nchar(10));
create table dianbiao1001 using super_dianbiao tags('张三','东城小区','1-1101');
create table dianbiao1002 using super_dianbiao tags('李四','东城小区','1-1102');
insert into dianbiao1001 values(now,1.7,3.2);
TDengine example diagram
TDengine example diagram
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLTDengineIoTTime Seriessuper table
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.