Getting Started
Make sure to first set up your PlanetScale developer environment. Once you’ve installed thepscale 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.Available flags
Available roles for the
--role flag are:
reader- Read-only accesswriter- Write-only accessreadwriter- Read and write accessadmin- Full administrative access
--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):exit (MySQL) or \q (Postgres) to exit the shell.
Using replica connections
Connect to a read-only replica: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:
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.
