docs/en/04-get-started/_get_started.mdx
To easily check the status of TDengine TSDB and perform various ad-hoc database queries, TDengine TSDB provides a command-line interface. To enter the TDengine CLI, simply execute taos (on Linux/Mac) or taos.exe (on Windows) in your terminal. The prompt appears as:
taos>
In the TDengine TSDB CLI, you can use SQL commands to create or delete databases and tables, as well as perform data insertion and query operations. Each SQL statement executed in the terminal must end with a semicolon (;). For example:
CREATE DATABASE demo;
USE demo;
CREATE TABLE t (ts TIMESTAMP, speed INT);
INSERT INTO t VALUES ('2019-07-15 00:00:00', 10);
INSERT INTO t VALUES ('2019-07-15 01:00:00', 20);
SELECT * FROM t;
ts | speed |
========================================
2019-07-15 00:00:00.000 | 10 |
2019-07-15 01:00:00.000 | 20 |
Query OK, 2 row(s) in set (0.003128s)
You can also use the TDengine TSDB CLI to monitor system status, manage users, and perform administrative tasks.
The CLI and client drivers can be installed separately on other machines. For more details, see TDengine CLI Reference.
taosBenchmark is a tool designed to evaluate TDengine’s performance in data ingestion, querying, and subscription. It can simulate data generated by numerous devices, allowing flexible configuration of database, supertable, tag columns, data columns, subtable counts, record counts, data intervals, number of threads, and whether to include out-of-order data.
To use taosBenchmark, ensure that TDengine is installed and running, and then execute the following command:
taosBenchmark -y
This automatically creates a database named test containing a supertable named meters. Within the supertable, 10,000 subtables named d0 through d9999 are generated, each containing 10,000 records. Each record has four fields: ts (timestamp), current, voltage, and phase, with timestamps ranging from 2017-07-14 10:40:00 000 to 2017-07-14 10:40:09 999. Each table also contains two tags: location and groupId, where groupId ranges from 1 to 10 and location includes cities in California such as California.Campbell and California.Cupertino.
After executing the taosBenchmark command, the system quickly writes 100 million records. The time required depends on your hardware, but on an average server, this process typically takes only a few seconds.
To customize testing parameters such as table counts or record numbers, taosBenchmark provides a wide range of options. To see all available parameters, run the following command:
taosBenchmark --help
For detailed usage instructions, see taosBenchmark Reference.
After inserting data with taosBenchmark, you can run the following queries in the TDengine CLI to verify query performance.
Count total records in the supertable meters:
SELECT COUNT(*) FROM test.meters;
Calculate the average, maximum, and minimum of all records:
SELECT AVG(current), MAX(voltage), MIN(phase) FROM test.meters;
Count records where location = California.SanFrancisco:
SELECT COUNT(*) FROM test.meters WHERE location = "California.SanFrancisco";
Query the average, maximum, and minimum for all records where groupId = 10:
SELECT AVG(current), MAX(voltage), MIN(phase) FROM test.meters WHERE groupId = 10;
Aggregate table d1001 in 10-second intervals and compute averages, maxima, and minima:
SELECT _wstart, AVG(current), MAX(voltage), MIN(phase) FROM test.d1001 INTERVAL(10s);
:::note
In the above query, the pseudocolumn _wstart represents the start time of each aggregation window.
:::
TDengine TSDB Explorer is a web-based interface that allows you to manage and interact with TDengine directly from your browser.
To use TDengine TSDB Explorer, access its address in a web browser. The default port is 6060. For example, if TDengine is running locally, visit http://localhost:6060.
Enter your username and password and click Login. The default username is root and password taosdata.
If you have not logged in to TDengine TSDB Explorer before, you must register first. Enter your name and email address and click Get verification code. Then enter the verification code sent to your email address and click Submit.
After logging in, the Explorer page is displayed, where you can view databases, supertables, subtables, and run SQL queries.
On the Programming page, you can view client library examples for various programming languages, all of which can be executed directly via copy/paste.
The Tools page lists visualization tools that integrate with TDengine such as Grafana and Power BI. You can follow the on-screen guidance to create dashboards and reports easily.
Click the ? icon in the upper-right corner of the interface to access the TDengine documentation. This is installed locally and does not require an internet connection.
Grafana is a popular open-source platform for data visualization and monitoring. TDengine integrates seamlessly with Grafana to create dashboards and alert systems, all without writing a single line of code. The example below uses smart meter data generated by taosBenchmark to create a panel that displays current fluctuations.
Install and start Grafana (version 8.0 or above is supported).
Insert test data using the following command, which creates a supertable meters in the test database with 100 subtables, each containing 1,000 records starting from one hour ago:
taosBenchmark --start-timestamp=$(date --date="1 hours ago" +%s%3N) \
--time-step=1000 --records=1000 \
--tables=100 --answer-yes
Communication between Grafana and TDengine is handled via the TDengine Datasource plugin.
On Linux, you can install the plugin by running the following command:
bash -c "$(curl -fsSL https://raw.githubusercontent.com/taosdata/grafanaplugin/master/install.sh)"
For other platforms, refer to the plugin installation guide.
After installation, restart the Grafana service:
sudo systemctl restart grafana-server.service
In Grafana, go to Connections > Add new connection, search for TDengine, and click Add new data source.
Configure the data source as follows:
http://localhost:6041.Click Save & test. If you see the message TDengine Data source is working, the connection is successful.
Select Dashboards > New and click Add a new panel. Choose the TDengine data source that you configured earlier.
In the Input SQL field, enter the following query and click Apply. This displays the average variation of the current column:
SELECT _wstart AS ts, avg(voltage) AS voltage, avg(phase) AS phase FROM test.meters
WHERE groupid =1 and ts > $from AND ts < $to interval($interval) fill(null)
For more details, see Grafana.
TDengine TSDB can ingest data from various sources, including PI System, OPC, InfluxDB, MQTT, Kafka, CSV, MySQL, PostgreSQL, Oracle, and MongoDB.
The following example shows how to create an MQTT data ingestion task to subscribe to data from an MQTT broker and write it into TDengine.
In a web browser, access TDengine TSDB Explorer.
From the main menu on the left, select Data In.
On the Data In Task tab, click + Add Source to open the task configuration page.
Configure the MQTT task as follows:
test-mqtt as the name, and click Create.Configure the connection and authentication:
broker.emqx.io1883Configure MQTT protocol settings:
tdengine-topic1::0Click Check Connectivity. If the message Your data source is reachable appears, the connection is successful.
Configure payload transformation:
{ "id": 1, "current": 10.42, "phase": 1.38, "voltage":200, "groupid": 7, "location": "beijing" }
Click the Preview icon on the right to preview parsing results.
Under Mapping, create a supertable with the following schema:
Columns:
| Data Type | Name |
|---|---|
| TIMESTAMP | ts |
| INT | id |
| DOUBLE | current |
| DOUBLE | phase |
| INT | voltage |
Tags:
| Data Type | Name |
|---|---|
| INT | groupid |
| VARCHAR(128) | location |
After creating and selecting the supertable, click Submit.
Your task is now displayed in the Data In Task list. When its status changes to Running, data from the MQTT topic will be consumed and written into TDengine TSDB automatically.
You can use the MQTT client tool MQTTX to send test data. For more information, see the documentation.
Use the same broker and topic configuration as your MQTT task:
Broker Address: broker.emqx.io
Port: 1883
Topic: tdengine-topic1
Sample Data:
{ "id": 1, "current": 10.42, "phase": 1.38, "voltage":200, "groupid": 7, "location": "beijing" }
After sending test data, you can check whether it has been successfully written to TDengine TSDB. In TDengine TSDB Explorer, run the following SQL statement:
SELECT * FROM `test-mqtt`.`meters`;
If data is returned, it confirms successful ingestion.
You can also view the task’s running status, ingestion rate, and error logs on the Data In page.
After completing this quick start, you can continue exploring TDengine’s advanced capabilities and features.