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.
Usage:
Available flags
Flag | Description |
---|---|
-h , --help | Help for shell command |
--local-addr <ADDRESS> | Local address to bind and listen for connections. By default the proxy binds to 127.0.0.1 with a random port. |
--org <ORGANIZATION_NAME> | The organization for the current user |
--remote-addr <ADDRESS> | PlanetScale Database remote network address. By default the remote address is populated automatically from the PlanetScale API |
--replica | When enabled, the password will route all reads to the branch’s primary replicas and all read-only regions |
--role <ROLE> | Role defines the access level, allowed values are: reader, writer, readwriter, admin. Defaults to ‘reader’ for replica passwords, otherwise defaults to ‘admin’ |
--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
Command | Description |
---|---|
--api-token <TOKEN> | The API token to use for authenticating against the PlanetScale API |
--api-url <URL> | The base URL for the PlanetScale API (default https://api.planetscale.com/ ) |
--config <CONFIG_FILE> | Config file (default is $HOME/.config/planetscale/pscale.yml ) |
--debug | Enable debug mode |
-f , --format <FORMAT> | Show output in a specific format. Possible values: human (default), json , csv |
--no-color | Disable color output |
--service-token <TOKEN> | Service Token for authenticating |
--service-token-id <TOKEN_ID> | The Service Token ID for authenticating |
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:
NoteWhen 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.