Get Started with TiDB Cloud CLI
TiDB Cloud CLI (ti) is a command-line tool for managing TiDB Cloud Starter instances and file systems in TiDB Cloud Filesystem. 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. The keys must have the Organization Owner access to your organization.
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-west-2). 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 fs list-file-systemsExample output:
{ "region_code": "aws-us-west-2", "file_systems": [] }
Step 3. Choose a workflow
Proceed with either of the following workflows based on your needs:
Option A: TiDB Cloud Filesystem
TiDB Cloud Filesystem is a persistent, shareable cloud file system that you can use across local machines, CI jobs, sandboxes, and other ephemeral environments.
The following example shows how you can create a file system in one environment and access it from the same or another environment. For example, you can access it from an AI agent sandbox (a temporary environment that might be discarded after a task).
On your local machine or another environment with your TiDB Cloud API credentials configured, create a file system and obtain its owner token:
export TI_FS_TOKEN="$(ti fs create-file-system --display-name agent-workspace --wait --query fs_token --output text --region aws-us-west-2)"In the environment where you want to use the file system, set the owner token from the previous step as
TI_FS_TOKEN, and then mount the file system to a local path as follows. This environment can be the same machine where you created the file system, another machine, or an AI agent sandbox.# export TI_FS_TOKEN="<owner-token>" # If you are continuing on a different environment as step 1, pass in the TI_FS_TOKEN you get from step 1 here. mkdir ~/mnt-test ti fs mount-file-system --mount-path ~/mnt-test --region aws-us-west-2 echo 'Hello from TiDB Cloud Filesystem' >> ~/mnt-test/hello.txt ls -l ~/mnt-test/hello.txtAfter mounting, you can work with the files using standard local file operations.
After you finish using the mounted file system in that environment, unmount it:
ti fs unmount-file-system --mount-path ~/mnt-test --region aws-us-west-2Unmounting removes the local mount, but the files remain in TiDB Cloud Filesystem and can be accessed again from the same or another environment.
Option B: TiDB Cloud Starter
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.Generate the connection string:
export DATABASE_URL="$(ti db format-db-connection-string \ --db-cluster-id "$TI_DB_CLUSTER_ID" \ --read-write --query connection_string \ --output text)"
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 TiDB Cloud Filesystem.
- 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.