Lindorm-cli is a lightweight command line interface provided by Lindorm for connecting to and managing Lindorm databases. You can use Lindorm-cli to perform basic SQL operations such as creating tables, querying data, and writing data. This topic describes how to connect to and use the Lindorm time series engine.
Prerequisites
Add your client IP address to the Lindorm whitelist. For more information, see Set a whitelist.
Step 1: Install Lindorm-cli
Download the Lindorm-cli installation package for your operating system. The download links are listed in the following table.
NoteThe SHA256 checksums in the table verify the integrity and authenticity of the downloaded Lindorm-cli packages.
Operating system
Download link
SHA256 checksum
Linux
To download from the command line:
wget https://tsdbtools.oss-cn-hangzhou.aliyuncs.com/lindorm-cli-linux-latest.tar.gz3a9ee33e24769cf47b3a90c3a1bba29d26f8aede7a64dbc13ea1f4f5426f04e4
Linux-arm64
To download from the command line:
wget https://tsdbtools.oss-cn-hangzhou.aliyuncs.com/lindorm-cli-linux-arm64-latest.tar.gzbc723d4a3a14a85c973c7082a56bb4934a40d2b9cccd72b5767352b8c334ce19
Mac (Intel chip)
34efd3f43a700e1fea72ee5e5933b9df3cf624569bcf59a2f8a6752dc7faab6c
Mac (Apple silicon)
0be9b346404a37d953714377b59f06b6492ff9c4e46dba4d5bf07c390ee284ad
Windows
0be9b346404a37d953714377b59f06b6492ff9c4e46dba4d5bf07c390ee284ad
Extract the installation package.
For Linux, run the following command to extract the package:
tar zxvf lindorm-cli-linux-latest.tar.gzAfter extraction, the
lindorm-cli-linux-latestfolder contains thelindorm-clifile.
Step 2: Connect to the Lindorm time series engine
Client deployed on Linux or Mac
Go to the directory that contains the
lindorm-clifile.cd <lindorm-cli directory>Run the following command to connect to the time series engine:
./lindorm-cli -url <Lindorm time series SQL endpoint> -username <username> -password <password> -database <target database name>Connection example
./lindorm-cli -url jdbc:lindorm:tsdb:url=http://ld-4xo90g5i370cu****-proxy-tsdb.lindorm.rds.aliyuncs.com:8242 -username user -password test -database defaultParameter description
Parameter
Required
Description
Lindorm time series SQL endpoint
Yes
The time series SQL endpoint of the Lindorm time series engine. Example:
jdbc:lindorm:tsdb:url=http://ld-bp12pc23yfb3*****-proxy-tsdb-pub.lindorm.rds.aliyuncs.com:8242.NoteThe Lindorm-cli connection method also supports the time series HTTP endpoint.
Username
No
The username for connecting to the Lindorm time series engine.
If user authentication and permission verification are disabled for the time series engine, you do not need to specify a username or password. For more information, see User and permission management.
Password
No
The password for connecting to the Lindorm time series engine. If you forget your password, reset it in the cluster management system of the Lindorm wide-table engine. For more information, see Change user passwords.
Target database name
No
The database to connect to using Lindorm-cli. The default database is default. During the session, switch to another database by running
use <target database name>.A successful connection returns the following output:
lindorm-cli version: 1.0.xxHere,
1.0.xxis the Lindorm-cli version number.
Client deployed on Windows
Method 1
Open Command Prompt (CMD) and go to the directory that contains
lindorm-cli.exe.cd <lindorm-cli.exe directory>In CMD, run the following command to connect to the time series engine:
lindorm-cli -url <Lindorm time series SQL endpoint> -username <username> -password <password> -database <target database name>A successful connection returns the following output:
Connected to jdbc:lindorm:tsdb:url=http://****-proxy-tsdb-pub.lindorm.rds.aliyuncs.com:8242 lindorm-cli version: 1.0.xxHere,
1.0.xxis the Lindorm-cli version number.
Method 2
Double-click Lindorm-cli.exe to open the program and run the following command:
connect <Lindorm time series SQL endpoint> <username> <password> -database <target database name>A successful connection returns no output.
Step 3: Use the Lindorm time series engine
Create a table
Create a time series table.
CREATE TABLE sensor ( device_id VARCHAR NOT NULL, region VARCHAR NOT NULL, time TIMESTAMP NOT NULL, temperature DOUBLE, humidity BIGINT, PRIMARY KEY(device_id, region, time) );NoteWhen creating a time series table, specify a primary key (PRIMARY KEY). The Basic Edition does not support PRIMARY KEY. Typically, use a unique identifier from your data source as the PRIMARY KEY. Examples include device ID in Internet of Things scenarios, vehicle ID in Internet of vehicles scenarios, application ID in monitoring scenarios, or
ip:port.The column name for the timestamp must be time, which represents the data timestamp in milliseconds (ms).
Verify that the table sensor was created successfully.
SHOW TABLES;The query result is as follows:
+-------------------+ | Tables_In_default | +-------------------+ | sensor | +-------------------+View the columns of the time series table.
DESCRIBE TABLE sensor;The query result is as follows:
+-------------+-----------+------------+------------+--------------+ | columnName | typeName | columnKind | primaryKey | partitionTag | +-------------+-----------+------------+------------+--------------+ | device_id | VARCHAR | TAG | true | true | | region | VARCHAR | TAG | true | true | | time | TIMESTAMP | TIMESTAMP | true | false | | temperature | DOUBLE | FIELD | false | false | | humidity | BIGINT | FIELD | false | false | +-------------+-----------+------------+------------+--------------+
Write data
If two data points have identical tag values and timestamps, they are considered the same data point. The later write overwrites the earlier one.
Write data one row at a time.
INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1260','north-cn','2021-04-22 15:33:00',12.1,45); INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1260','north-cn','2021-04-22 15:33:10',13.2,47); INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1260','north-cn','2021-04-22 15:33:20',10.6,46); INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1261','south-cn','2021-04-22 15:33:00',18.1,44); INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES('F07A1261','south-cn','2021-04-22 15:33:10',19.7,44);Write data in batches.
INSERT INTO sensor (device_id, region, time, temperature, humidity) VALUES ('F07A1260','north-cn','2021-04-22 15:33:00',12.1,45), ('F07A1260','north-cn','2021-04-22 15:33:10',13.2,47), ('F07A1260','north-cn','2021-04-22 15:33:20',10.6,46), ('F07A1261','south-cn','2021-04-22 15:33:00',18.1,44), ('F07A1261','south-cn','2021-04-22 15:33:10',19.7,44);
Query data
Conditional query
Query data for device F07A1260 between 2021-04-22 15:33:00 and 2021-04-22 15:33:20:
SELECT device_id,region,time,temperature,humidity FROM sensor WHERE device_id = 'F07A1260' AND time >= '2021-04-22 15:33:00' AND time <= '2021-04-22 15:33:20';The query result is as follows:
+-----------+----------+---------------------------+-------------+----------+
| device_id | region | time | temperature | humidity |
+-----------+----------+---------------------------+-------------+----------+
| F07A1260 | north-cn | 2021-04-22T15:33:00+08:00 | 12.1 | 45 |
| F07A1260 | north-cn | 2021-04-22T15:33:10+08:00 | 13.2 | 47 |
| F07A1260 | north-cn | 2021-04-22T15:33:20+08:00 | 10.6 | 46 |
+-----------+----------+---------------------------+-------------+----------+Downsampling query
A downsampling query reduces the sample rate of time series data to decrease the number of data points in the result set.
The following example queries the temperature for device F07A1260 between 2021-04-22 15:33:00 and 2021-04-22 15:33:20, downsamples the data every 20 seconds, and returns the maximum value:
SELECT device_id,region,time,max(temperature) AS max_temperature FROM sensor WHERE device_id = 'F07A1260' AND time >= '2021-04-22 15:33:00' AND time <= '2021-04-22 15:33:20' SAMPLE BY 20s;The query result is as follows:
+-----------+----------+---------------------------+-----------------+
| device_id | region | time | max_temperature |
+-----------+----------+---------------------------+-----------------+
| F07A1260 | north-cn | 2021-04-22T15:33:00+08:00 | 13.2 |
| F07A1260 | north-cn | 2021-04-22T15:33:20+08:00 | 10.6 |
+-----------+----------+---------------------------+-----------------+Aggregate query
Calculate the maximum temperature across all regions:
SELECT region,max(temperature) AS max_temperature FROM sensor WHERE time >= '2021-04-22 15:33:00' AND time <= '2021-04-22 15:33:20' GROUP BY region;The query result is as follows:
+----------+-----------------+
| region | max_temperature |
+----------+-----------------+
| north-cn | 13.2 |
| south-cn | 19.7 |
+----------+-----------------+Common Lindorm-cli commands
help: View help.connect: Connect to a server.precision: Set the time display format. Supported formats: rfc3339, h, m, s, ms, u, or ns.exitorquit: Exit the current connection to the Lindorm time series engine.
FAQ
Why is the query result empty after successful data insertion?
If a query returns no data after a successful write, check whether the database has a time-to-live (TTL) setting by running DESCRIBE DATABASE <database name>. Data older than the TTL is automatically deleted and cannot be queried.
Can Lindorm-cli import or export time series data?
For small data volumes, you can use Lindorm-cli to quickly import or export CSV files. Contact Lindorm technical support (DingTalk ID: s0s3eg3) if needed.
For large data volumes, import data using DataX. Exporting large-scale data is not supported.