Connect to your database

This document describes how to connect to your PlanetScaleDB database or Database Link using a MySQL connection string.

Prerequisites

This document assumes you have created a database.

This document uses the MySQL command line client as an example MySQL client; however, you can connect to your database using any MySQL client.

Overview

To create a Database, follow these steps:

  1. Go to the PlanetScale console.
  2. Click on your cluster.
  3. Click on your database.
  4. Click the Connect button.
  5. Click the Copy button next to your connection string.
  6. Paste the connection string into a MySQL client.
  7. Connect to your database using the MySQL client.

Step 1. Go to the PlanetScale console.

This opens the Clusters Overview.

Step 2. Click on your cluster name.

This opens the Overview for your cluster.

Step 3. Click on your database name.

This opens the Overview for your database.

Step 4. Click the Connect button.

This opens the connection pane. This pane shows the MySQL connection string for each region and cloud provider where this database is deployed.

Step 5. Click the Copy button next to your connection string.

Click the Copy button next to the connection string for the desired region. This copies the connection string to your clipboard.

Step 6. Paste the connection string into a MySQL client.

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:

console
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:

console
cat << EOF > ~/.my.cnf
[client]
user=vtgate-1-user
password=aAbBcCdDeE12345
host=abcdefghijklmnop-123456789.us-east-1.elb.amazonaws.com
port=3306
EOF

Step 7. Connect to your database using the MySQL client.

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:

console
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.