This document describes how to connect to your PlanetScale database using a MySQL connection string.
This document assumes you have created a PlanetScale database.
This document uses the MySQL command line client as an example MySQL client; however, you can connect to your PlanetScale database using any MySQL client.
To create a PlanetScale Database, follow these steps:
This opens the Clusters Overview.
This opens the Overview for your database.
This opens the connection pane.
The connection panel displays your MySQL connection string for each region. Click the Copy button next to the connection string for the desired region.
This copies the connection string to your clipboard.
The connection string contains the user credentials for your PlanetScale database, formatted as a MySQL client command line command. To connect to the database with a client, paste the connection string into the appropriate location for your client.
For example, to connect using the MySQL command line client, you can paste the connection string into a your terminal. It should look like the following:
mysql --host abcdefghijklmnop-123456789.us-east-1.elb.amazonaws.com --port 3306 --user vtgate-1-user --password=aAbBcCdDeE12345
Note: MySQL discourages specifying passwords in plaintext on the command line. To improve password security, configure the MySQL command line to default to your PlanetScale database connection settings. For example:
cat << EOF > ~/.my.cnf [client] user=vtgate-1-user password=aAbBcCdDeE12345 host=abcdefghijklmnop-123456789.us-east-1.elb.amazonaws.com port=3306 EOF
Using your MySQL client, request a MySQL connection using the connection string. For example, using the MySQL command line client, enter the command from Step 5 above. Your MySQL client should indicate that there is now a connection to your PlanetScale database, and prompt for MySQL queries.
For example, assuming that you have a configuration file from Step 5 above, you can run the MySQL command line client with no arguments, and it will connect to your PlanetScale database:
shell> mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12669 Server version: 5.5.10-Vitess MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
You can now issue queries against your PlanetScale database.