Integrate a serverless PlanetScale MySQL database to your application and benefit from native autoscaling, automatic HTTPS (SSL), auto-healing, and global load-balancing across our edge network with zero configuration.
PlanetScale
Using a PlanetScale database lets you benefit from powerful features like horizontal sharding, non-blocking schema changes, and data branching without having to implement them.
Plus, you can deploy your PlanetScale database in multiple regions
This guide explains how to connect a PlanetScale MySQL database to an application running on Koyeb. To successfully follow this documentation, you will need to have:
The application that connects to the PlanetScale MySQL database uses Prisma as an ORM. Prisma is an open-source ORM. We use it to synchronize our database schema with our Prisma schema.
If you already have a freshly created PlanetScale database running and want to quickly preview how to connect your PlanetScale database to an application running on Koyeb, use the Deploy to Koyeb button below.
Make sure to replace the DATABASE_URL
environment variable with the connection string of your PlanetScale database.
To create a PlanetScale MySQL database, sign into your PlanetScale account
On the PlanetScale control panel, click the Create database button. A database creation modal will pop up.
planetscale-koyeb
When you are done configuring your database, click the Create database button. The database will be initialized and provisioned.
On your PlanetScale database page, click the Connection button. On this dialog, click the New password button to generate a unique username and password pair that you can use to access the main
branch of your database.
Store this password in a safe place, you will not be able to view it again.
Since we will be using Prisma as an ORM for the sample application that we are deploying in this demo, select Prisma
in the "Connect with" dropdown menu.
The connection string will be similar to the following:
DATABASE_URL='mysql://<user>:<password>@us-east.connect.psdb.cloud/<database>?sslaccept=strict'
Copy the connection string and make sure to save it in a safe place, we will use it when we deploy the application.
You can deploy the sample application connected to a PlanetScale database on Koyeb using the control panel or via the Koyeb CLI.
To deploy the using the
control panel
github.com/koyeb/example-express-prisma
as the GitHub repository to
deploy and keep the default branch main
npm run mysql:init
as the Build command DATABASE_URL
environment variable to indicate the application how to
connect to the PlanetScale database. Give the environment variable a name,
DATABASE_URL
and enter the connection string from earlier as the
valueexpress-planetscale
Koyeb is now building the application. Once the build has finished, you will be able
to access your application running on Koyeb by clicking the URL ending with
.koyeb.app
.
The example application exposes a /planets
endpoint that you can use to list
planets from the database. Once your deployment is live, you should see the
following results when navigating to https://<YOUR_APP_URL>.koyeb.app/planets
:
[ { "id": 1, "name": "Mercury" }, { "id": 2, "name": "Venus" }, { "id": 3, "name": "Mars" } ]
To deploy the example application using the Koyeb CLI, run the following command in your terminal:
koyeb app init express-planetscale \ --git github.com/koyeb/example-express-prisma \ --git-branch main \ --git-build-command "npm run mysql:init" \ --ports 8080:http \ --routes /:8080 \ --env PORT=8080 \ --env DATABASE_URL="mysql://<user>:<password>@us-east.connect.psdb.cloud/<database>?sslaccept=strict"
Make sure to replace user
, password
, and database
with your own.
Access deployment logs
To track the app deployment and visualize build logs, execute the following command:
koyeb service logs express-planetscale/express-planetscale -t build
Access your app
Once the deployment of your application has finished, you can retrieve the public domain to access your application by running the following command:
$ koyeb app get express-planetscale ID NAME DOMAINS CREATED AT ec6a4311 express-planetscale ["express-planetscale-myorg.koyeb.app"] 10 Mar 23 10:12 UTC
The example application exposes a /planets
endpoint that you can use to list
planets from the database. Once your deployment is live, you should see the
following results when navigating to https://<YOUR_APP_URL>.koyeb.app/planets
:
[ { "id": 1, "name": "Mercury" }, { "id": 2, "name": "Venus" }, { "id": 3, "name": "Mars" } ]
To delete the example application and the PlanetScale database and avoid incurring any charges, follow these steps: