📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

ti db format-db-connection-string



Formats stored SQL credentials for read-write, read-only, or admin access. The command verifies that the cluster is Starter before loading its local SQL credentials.

Syntax

ti db format-db-connection-string --db-cluster-id <string> [--admin] [--database <string>] [--env-database-url-name <string>] [--env-include-database-url] [--env-prefix <string>] [--format <string>] [--help] [--read-only] [--read-write] [--version]

Options

  • --db-cluster-id <string>: Starter DB cluster ID. [required]
  • --admin: Use prepared admin DB SQL credentials.
  • --database <string>: Database/default schema name.
  • --env-database-url-name <string>: Database URL variable name for --format env. [default: DATABASE_URL]
  • --env-include-database-url: Include a database URL variable with --format env.
  • --env-prefix <string>: Dotenv variable prefix for --format env. [default: TIDB_]
  • --format <string>: Connection string format: mysql-uri, jdbc, go-sql-driver, sqlalchemy, or env. [default: mysql-uri]
  • --help: Display help information.
  • --read-only: Use prepared read_only DB SQL credentials.
  • --read-write: Use prepared read_write DB SQL credentials.
  • --version: Display version information.

For options shared by all commands, see Global options.

Examples

  • Format a read-write MySQL URI:

    # Use the default application role in tools that accept a MySQL URI. ti db format-db-connection-string --db-cluster-id "<cluster-id>" --read-write --format mysql-uri
  • Format read-only dotenv variables:

    # Emit environment assignments for a workload that must not modify data. ti db format-db-connection-string --db-cluster-id "<cluster-id>" --read-only --format env --env-prefix TIDB_
  • Format an admin JDBC URL:

    # Generate a JDBC connection value with the prepared admin credentials. ti db format-db-connection-string --db-cluster-id "<cluster-id>" --admin --format jdbc --database app
  • Include DATABASE_URL in dotenv output:

    # Emit both component variables and a conventional DATABASE_URL value. ti db format-db-connection-string --db-cluster-id "<cluster-id>" --format env --env-include-database-url

Was this page helpful?