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 move-tables command

Run Vitess MoveTables workflows on a Vitess database branch: copy tables from one keyspace to another, check copy and traffic state, switch reads then writes, and complete or cancel the workflow. Use it to shard tables, change the number of shards, and import an external MySQL database from an external keyspace. move-tables prints JSON. The output includes a next_steps field with a suggested next command. Use it to see what to run after list or status. Pass --format json when you script move-tables, so progress messages don’t mix with the JSON. Usage:
pscale branch vtctld move-tables also works.
You must be an Organization Administrator or a Database Administrator of the database to create and change workflows. Service tokens need read_workflow to list and view workflows, write_workflow to create, start, stop, switch traffic, and complete them, and delete_workflow to cancel them.

Available sub-commands

* Flag is required † Pass either --tables or --all-tables
list also accepts the alias ls.

Sub-command flag descriptions

Write boolean flags with an =, such as --keep-data=false. A space-separated value such as --keep-data false is read as --keep-data=true.

Available flags

Global flags

Lifecycle

A typical MoveTables run looks like this:
  1. Create the workflow and wait until copy finishes and streams are Running.
  2. Verify with pscale branch vtctl vdiff create, then vdiff show until it completes with no mismatches. You can skip VDiff and switch replica traffic directly.
  3. Switch replica traffic with --tablet-types REPLICA,RDONLY.
  4. Switch primary traffic with --tablet-types PRIMARY.
  5. Preview cleanup with complete --dry-run, then complete after you review the result.
Use status between steps. Each stream’s state is Copying, Running, Lagging, Stopped, or Error. traffic_state values are:
  • Reads Not Switched. Writes Not Switched
  • All Reads Switched. Writes Not Switched
  • Reads Not Switched. Writes Switched
  • All Reads Switched. Writes Switched
Use stop to pause a workflow and start to resume it, for example after it stops on a schema change. Until you complete a workflow, you can switch traffic back with reverse-traffic or cancel it. You can also follow each workflow on the Workflows page in the dashboard. The page is read-only.

Examples

List MoveTables workflows and get the next command to run:
Create a workflow:
Check copy and traffic state:
Example status JSON after replica traffic has switched:
Switch replica traffic, then primary traffic:
Verify with VDiff before switching traffic:
Preview cleanup, then complete:

Import from an external keyspace

After you create an external keyspace, move its tables into your PlanetScale keyspace:
When you complete an import, --keep-data must be true, so the tables in your source database are never dropped:
See Database imports for the full import walkthrough.

Need help?

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