08-taos-shell.md 4.5 KB
Newer Older
D
dingbo 已提交
1
---
2
title: TDengine Command Line (CLI)
D
dingbo 已提交
3
sidebar_label: TDengine CLI
4
description: Instructions and tips for using the TDengine CLI
D
dingbo 已提交
5 6
---

7
The TDengine command-line application (hereafter referred to as `TDengine CLI`) is the most feasility way for users to manipulate and interact with TDengine instances.
D
dingbo 已提交
8

9
## Installation
D
dingbo 已提交
10

11
If executed on the TDengine server-side, there is no need for additional installation steps to install TDengine CLI as it is already included and installed automatically. To run TDengine CLI on the environemtn which no TDengine server running, the TDengine client installation package needs to be installed first. For details, please refer to [connector](/reference/connector/).
D
dingbo 已提交
12

13
## Execution
D
dingbo 已提交
14

15
To access the TDengine CLI, you can execute `taos` command-line utility from a Linux terminal or Windows terminal.
D
dingbo 已提交
16 17 18 19

```bash
taos
```
20 21

TDengine CLI will display a welcome message and version information if it successfully connected to the TDengine service. If it fails, TDengine CLI will print an error message. See [FAQ](/train-faq/faq) to solve the problem of terminal connection failure to the server. The TDengine CLI prompts as follows:
D
dingbo 已提交
22 23 24 25

```cmd
taos>
```
26
After entering the TDengine CLI, you can execute various SQL commands, including inserts, queries, or administrative commands.
D
dingbo 已提交
27

28
## Execute SQL script file
D
dingbo 已提交
29

30
Run SQL command script file in the TDengine CLI via the `source` command.
D
dingbo 已提交
31 32 33 34 35

```sql
taos> source <filename>;
```

36
## Adjust display width to show more characters
D
dingbo 已提交
37

38
Users can adjust the display width in TDengine CLI to show more characters with the following command:
D
dingbo 已提交
39 40 41 42 43

```sql
taos> SET MAX_BINARY_DISPLAY_WIDTH <nn>;
```

44
If the displayed content is followed by `...` you can use this command to change the display width to display the full content.
D
dingbo 已提交
45

46
## Command Line Parameters
D
dingbo 已提交
47

48
You can change the behavior of TDengine CLI by specifying command-line parameters. The following parameters are commonly used.
D
dingbo 已提交
49

50 51 52 53 54
- -h, --host=HOST: FQDN of the server where the TDengine server is to be connected. Default is to connect to the local service
- -P, --port=PORT: Specify the port number to be used by the server. Default is `6030`
- -u, --user=USER: the user name to use when connecting. Default is `root`
- -p, --password=PASSWORD: the password to use when connecting to the server. Default is `taosdata`
- -?, --help: print out all command-line arguments 
D
dingbo 已提交
55

56
And many more parameters.
D
dingbo 已提交
57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
- -c, --config-dir: Specify the directory where configuration file exists. The default is `/etc/taos`, and the default name of the configuration file in this directory is `taos.cfg`
- -C, --dump-config: Print the configuration parameters of `taos.cfg` in the default directory or specified by -c
- -d, --database=DATABASE: Specify the database to use when connecting to the server
- -D, --directory=DIRECTORY: Import the SQL script file in the specified path
- -f, --file=FILE: Execute the SQL script file in non-interactive mode
- -k, --check=CHECK: Specify the table to be checked
- -l, --pktlen=PKTLEN: Test package size to be used for network testing
- -n, --netrole=NETROLE: test scope for network connection test, default is `startup`, The value can be `client`, `server`, `rpc`, `startup`, `sync`, `speed`, or `fqdn`.
- -r, --raw-time: output the timestamp format as unsigned 64-bits integer (uint64_t in C language)
- -s, --commands=COMMAND: execute SQL commands in non-interactive mode
- -S, --pkttype=PKTTYPE: Specify the packet type used for network testing. The default is TCP. can be specified as either TCP or UDP when `speed` is specified to netrole parameter
- -T, --thread=THREADNUM: The number of threads to import data in multi-threaded mode
- -s, --commands: Run TDengine CLI commands without entering the terminal
- -z, --timezone=TIMEZONE: Specify time zone. Default is the value of current configruation file
- -V, --version: Print out the current version number
D
dingbo 已提交
73

74
Example.
D
dingbo 已提交
75 76 77 78

```bash
taos -h h1.taos.com -s "use db; show tables;"
```
79 80
## TDengine CLI tips

81 82 83
- You can use the up and down keys to iterate the history of commands entered
- Change user password: use `alter user` command in TDengine CLI to change user's password. The default password is `taosdata`.
- use Ctrl+C to stop a query in progress
84
- Execute `RESET QUERY CACHE` to clear the local cache of the table schema
85 86
- Execute SQL statements in batches. You can store a series of shell commands (ending with ;, one line for each SQL command) in a script file and execute the command `source <file-name>` in the TDengine CLI to execute all SQL commands in that file automatically
- Enter `q` to exit TDengine CLI