Get Started with TiDB Cloud CLI
TiDB Cloud CLI (ti) is a command-line tool for managing TiDB Cloud Starter instances and TiDB Cloud Filesystems. It supports both interactive use and automation, with JSON as the default output format for commands.
This guide walks you through installing and configuring TiDB Cloud CLI (ti), and then completing a basic workflow with TiDB Cloud Starter or TiDB Cloud Filesystem. For an overview of the CLI, its capabilities, and supported workflows, see TiDB Cloud Command Line Interface Overview.
Prerequisites
Before you begin, obtain a TiDB Cloud API public key and private key from the TiDB Cloud API Keys page in the TiDB Cloud console.
Step 1. Install TiDB Cloud CLI
Depending on your operating system, take the following steps to install TiDB Cloud CLI.
On macOS or Linux, run the following command to install TiDB Cloud CLI:
curl -fsSL https://github.com/tidbcloud/ti-cli/releases/latest/download/install.sh | sh -s -- --yesAdd
tito the current shell and verify it:export PATH="$HOME/.ti/bin:$PATH" ti --versionAdd
export PATH="$HOME/.ti/bin:$PATH"to your shell profile to keeptiavailable in new terminals.For example, if you use
zsh, run the following command:echo 'export PATH="$HOME/.ti/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
On Windows PowerShell, run the following command to install TiDB Cloud CLI:
$script = "$env:TEMP\install-ti.ps1" iwr https://github.com/tidbcloud/ti-cli/releases/latest/download/install.ps1 -OutFile $script powershell -ExecutionPolicy Bypass -File $script -YesAdd
tito the current PowerShell session and verify it:$env:Path = "$HOME\.ti\bin;$env:Path" ti --versionAdd
$HOME\.ti\binto your userPATHto keeptiavailable in new PowerShell sessions:$tiBin = "$HOME\.ti\bin" [Environment]::SetEnvironmentVariable("Path", "$tiBin;$([Environment]::GetEnvironmentVariable('Path', 'User'))", "User")
Step 2. Configure TiDB Cloud CLI
Run the interactive configuration:
ti configureProvide the following information:
- A default region for CLI operations, specified as a region code (such as
aws-us-east-1). For a list of regions that are supported by TiDB Cloud CLI, see Supported regions. - Your TiDB Cloud API public key and private key.
- A default region for CLI operations, specified as a region code (such as
Run a read-only command to verify that the CLI can access TiDB Cloud using the saved credentials:
ti db list-db-clusters --db-cluster-type starter --output textExample output:
{ "profile": "default", "region_code": "aws-us-east-1", "credentials_stored": true }
Step 3. Choose a workflow
Complete either of the following workflows.
- Option A: Create and use a Filesystem
- Option B: Create a TiDB Cloud Starter instance and query the database
Option A: Create and use a Filesystem
A TiDB Cloud Filesystem is a persistent, shareable cloud file system that you can use across local machines, CI jobs, sandboxes, and other ephemeral environments.
Create a Filesystem, wait until it is ready, and save its server-assigned ID:
export TI_FS_FILE_SYSTEM_ID="$(ti fs create-file-system \ --wait \ --query file_system_id \ --output text)"tistores the Filesystem credential locally, so you do not need to provide it for subsequent file operations.Write a file to the Filesystem, and then read the file:
printf 'hello from ti\n' | ti fs copy-file \ --from-stdin \ --to-remote /hello.txt ti fs read-file \ --path /hello.txtExpected output:
hello from tiDelete the Filesystem:
ti fs delete-file-system \ --file-system-id "$TI_FS_FILE_SYSTEM_ID" unset TI_FS_FILE_SYSTEM_ID
Option B: Create a TiDB Cloud Starter instance and query the database
Create a TiDB Cloud Starter instance and save its ID:
export TI_DB_CLUSTER_ID="$(ti db create-db-cluster \ --db-cluster-type starter \ --db-cluster-name quickstart-db \ --wait \ --query id \ --output text)"Create the SQL users and run a read-only query to verify the connection:
ti db create-db-sql-users \ --db-cluster-id "$TI_DB_CLUSTER_ID" ti db execute-sql-statement \ --db-cluster-id "$TI_DB_CLUSTER_ID" \ --read-only \ --sql "SELECT 1 AS ready" \ --output textThe
ti db execute-sql-statementcommand executes the query through the HTTPS SQL API. The output includesready = 1.Delete the TiDB Cloud Starter instance:
ti db delete-db-cluster \ --db-cluster-id "$TI_DB_CLUSTER_ID" \ --wait unset TI_DB_CLUSTER_ID
What's next
- Read the TiDB Cloud Command Line Interface Overview to understand what
timanages and when to use it. - Follow the task guides to manage TiDB Cloud Starter or Filesystem resources.
- Explore the TiDB Cloud CLI Command Reference for command groups, global options, and shared CLI behavior.
- Learn about TiDB Cloud CLI Configuration and Credentials to set up multiple profiles or non-interactive authentication.