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 shell command

This command opens a secure shell instance to your database so that you can manipulate it from the command line. For MySQL databases, it uses the MySQL command-line client (mysql). For Postgres databases, it uses the Postgres command-line client (psql). The appropriate client must be installed prior to use.
If your Managed cluster has public connectivity disabled, you must connect over PrivateLink. Set up the VPC endpoint using the service name we provide, make sure your DNS resolves your PlanetScale hostnames to that PrivateLink endpoint, and then run pscale shell mydatabase mybranch.If you use a VPN such as Tailscale, do not override psdb.cloud DNS in your VPN configuration. Split‑DNS misconfiguration can point hostnames at the wrong place and break shell connectivity.
Usage:
By default, if no branch names are given and there is only one branch, it automatically opens a shell to that branch. If there are multiple branches for the given database, you’ll be prompted to choose one.

Available flags

Available roles for the --role flag are:
  • reader - Read-only access
  • writer - Write-only access
  • readwriter - Read and write access
  • admin - Full administrative access
For replica connections (--replica flag), the default role is reader. For regular connections, the default role is admin.

Global flags

Examples

Basic shell usage

Open a shell to a database (auto-selects branch if only one exists):
Open a shell to a specific branch:
Once the shell is opened, you can run SQL as expected. Example MySQL session:
Example Postgres session:
Type exit (MySQL) or \q (Postgres) to exit the shell.

Using replica connections

Connect to a read-only replica:
Replica connections route all reads to the branch’s primary replicas, and defaults to reader role.

Using specific roles

Connect with a specific role:

Import an existing .sql file using the shell command

Command: The following example assumes you have already ran the pscale shell command and you have the shell open to run a MySQL command. To import an existing .sql file you may have available you would want to use the MySQL source command and provide it the path to your file:
Output: Your file should be imported as expected.
When importing .sql dump files there are a few caveats to be aware of as sometimes the .sql file may have everything wrapped in a START TRANSACTION; / COMMIT; transaction which will result in the import timing out if it takes more than 20 seconds to complete due to our 20 second transaction timeout limit so you will want to make sure those are removed prior to beginning an import of the file.Additionally, if your current schema requires our Vitess foreign key constraints support you may need to ensure it has been enabled within your database Settings area first before proceeding with your import.

Need help?

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