Skip to main content

Getting Started

Make sure to first set up your PlanetScale developer environment. Once you’ve installed the pscale CLI, you can interact with PlanetScale and manage your databases straight from the command line.

The sql command

Execute a single SQL query against a database branch without an interactive shell. Intended for agents and scripts. For interactive sessions, use pscale shell instead.
Requires pscale 0.292.0 or later.
Usage:
Place positional arguments first, then flags. --org is required.

Available flags

Unlike pscale shell, the default --role is reader. Pass --role admin (or writer / readwriter) for writes.

Destructive SQL

Queries containing DELETE, DROP, or TRUNCATE as statement keywords are blocked unless --force is passed. With --format json, blocked queries return "status": "action_required" and "query_kind": "destructive". Agents must ask the user to approve, then re-run with --force. Never use --force without explicit user approval.

JSON output

Use --format json for automation. Success: status, database, branch, kind (mysql, postgresql, or neki), role, row_count, columns, rows, and next_steps; rows_affected when applicable and replica when --replica was used. Neki databases use the PostgreSQL query path. Errors: one JSON object on stdout with status: "error", error, issues, and next_steps. Destructive guard: status: "action_required", query_kind: "destructive", message, issues, and next_steps (includes a --force retry command).

Global flags

Examples

Read query (default reader role):
Read from a PlanetScale Postgres or Vitess replica:
pscale sql --replica appends the Postgres |replica username suffix. That is not how Neki routes replica traffic. For Neki replica reads, use pscale shell --replica. Do not add |replica to a Neki username. Postgres or Neki with an explicit database name:
MySQL multi-keyspace:
Vertical output for wide rows:
Destructive SQL (after user approval):

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.