docs/en/14-reference/02-tools/07-taos-cli.md
The TDengine command line program (hereinafter referred to as TDengine CLI) is the simplest and most commonly used tool for users to operate and interact with TDengine instances. It requires the installation of either the TDengine Server package or the TDengine Client package before use.
TDengine CLI is the default installation component in the TDengine server and client installation package. It can be used after installation, refer to TDengine Installation
To enter the TDengine CLI, simply execute taos in the terminal.
taos
If the connection to the service is successful, a welcome message and version information will be printed. If it fails, an error message will be printed.
The TDengine CLI prompt is as follows:
taos>
After entering the TDengine CLI, you can execute various SQL statements, including insertions, queries, and various management commands.
To exit the TDengine CLI, execute q, quit, or exit and press enter.
taos> quit
You can change the behavior of the TDengine CLI by configuring command line parameters. Below are some commonly used command line parameters:
-h HOST: The FQDN of the server where the TDengine service is located, default is to connect to the local service.
-P PORT: Specifies the port number used by the server.
-u USER: Username to use when connecting.
-p PASSWORD: Password to use when connecting to the server. Special characters such as ! & ( ) < > ; | need to be escaped with \. Default value: taosdata.
-p parameter is not followed by a password string, the user will be prompted to enter the password, e.g., taos -u root -p.-p parameter is directly followed by a password string, that password will be used for connection, e.g., taos -u root -ptaosdata.-?, --help: Prints out all command line parameters.
-s COMMAND: SQL command executed in non-interactive mode.
Use the -s parameter to execute SQL non interactively, and exit after execution. This mode is suitable for use in automated scripts.
For example, connect to the server h1.taos.com with the following command, and execute the SQL specified by -s:
taos -h my-server -s "use db; show tables;"
-c CONFIGDIR: Specify the configuration file directory.
In Linux, the default is /etc/tao. The default name of the configuration file in this directory is taos.cfg.
Use the -c parameter to change the location where the taosc client loads the configuration file. For client configuration parameters, refer to Client Configuration.
The following command specifies the taos.cfg configuration file under /root/cfg/ loaded by the taosc client.
taos -c /root/cfg/
taos.cfg in the directory specified by -c.client, options are client, server.-q parameter is not followed by a token string, the user will be prompted to enter the token, e.g., taos -u root -q.-q parameter is directly followed by a token string, that token will be used for connection, e.g., taos -u root -q<token_string>.>> to export query results to a file, the syntax is: sql query statement >> 'output file name'; If no path is written for the output file, it will be output to the current directory. For example, select * from d0 >> '/root/d0.csv'; will output the query results to /root/d0.csv.insert into d0 file '/root/d0.csv'; means to import all the data exported above back into the d0 table.In the TDengine CLI, you can run multiple SQL commands from a script file using the source command, multiple SQL statements in the script file can be written in line.
taos> source <filename>;
\ + TAB key, will automatically complete to the column display mode command word \G;.You can adjust the display character width in the TDengine CLI using the following command:
taos> SET MAX_BINARY_DISPLAY_WIDTH <nn>;
If the displayed content ends with ..., it indicates that the content has been truncated. You can modify the display character width with this command to display the full content.
alter user command to change user passwords, the default password is taosdata.RESET QUERY CACHE to clear the cache of the local table Schema.;, each SQL statement on a new line) in a file, and execute the command source <file-name> in TDengine CLI to automatically execute all SQL statements in that file.Starting from TDengine version 3.3.4.8, TDengine CLI returns specific error codes in error messages. Users can visit the TDengine official website's error code page to find specific reasons and solutions, see: Error Code Reference