PlanetScale
Comprehensive guide for connecting to a PlanetScale Database from your DevBox.
If you're more of a visual learner, check out the video tutorial!
Architecture Diagram
PlanetScale is a MySQL based database service which is built on Vitess and unlocks performance, scalability, and cost optimization for hyperscale databases through horizontal sharding. In this guide, we will walk you through the entire process of connecting your PlanetScale Database to your DevBox.
Prerequisites
Before you begin, create your account with PlanetScale.
Existing PlanetScale Database
Step 1: Generating connection string
Follow the below steps to generate the connection string for database:
- Go to PlanetScale Dashboard.
- Click on the database you want to access.
- Click on Connect and click on Create password.
- Note down the Username and Password generated as it would not be displayed again.
- In the Select your language or framework choose the language or framework you want to connect your database with. For this guide, we will be going with MySQL CLI.
- Note down the connection string.
Step 2: Creating the Recipe for Workspace
You will need to create a Recipe in DevZero equipped with the necessary tools like mysql
:
- Go to DevZero Dashboard and open the Recipes tab.
- Click on New Recipe and enter the recipe's name.
- Click on Create a recipe, and your recipe will be created.
- Replace the recipe yaml file with the snippet below. Remember to replace the placeholder username and password with the value you noted down in the above steps:
- After editing the recipe, click on Save and Build.
- When the build is successful, click on Publish.
- After the recipe is published, click on Launch and create a new workspace by providing a Workspace Name.
- Click on Launch and your workspace will be created.
Step 3: Connecting to the Database
Now, with everything set, you just need to use the connection string to access the database:
- Go to DevBox.
- Use the following command to connect to the database:
New PlanetScale Workspace
If you need to make a new PlanetScale database and access it through DevBox, then follow the below steps:
Step 1: Creating a PlanetScale Database
- Go to PlanetScale Dashboard.
- Click on Create a new database and enter the Name and Region of your database instance.
- Then choose the Cluster size and Autoscaling storage and click on Create database.
- Enter the Password name when prompted.
- A Username and Password would be generated for you. Note down the password as it would not be displayed again.
- In the Select your language or framework choose the language or framework you want to connect your database with. For this guide, we will be going with MySQL CLI.
- Note down the connection string.
Step 2: Creating the Recipe for Workspace
You will need to create a Recipe in DevZero equipped with the necessary tools like mysql
:
- Go to DevZero Dashboard and open the Recipes tab.
- Click on New Recipe and enter the recipe's name.
- Click on Create a recipe, and your recipe will be created.
- Replace the recipe yaml file with the snippet below. Remember to replace the placeholder username and password with the value you noted down in the above steps:
- After editing the recipe, click on Save and Build.
- When the build is successful, click on Publish.
- After the recipe is published, click on Launch and create a new workspace by providing a Workspace Name.
- Click on Launch and your workspace will be created.
Step 3: Connecting to the Database
Now, with everything set, you just need to use the connection string to access the database:
- Go to DevBox.
- Use the following command to connect to the database: