title | subtitle | date |
---|---|---|
Deploy to Netlify |
Learn how to connect your PlanetScale database to deploy on Netlify |
2022-08-01 |
This guide will walk you through setting up and deploying your PlanetScale database on Netlify.
{% callout %} This doc is intended for users that are manually storing a connection string in an environment variable in Netlify. If you want to use the Netlify integration, which handles this for you, see the PlanetScale integration in the Netlify docs. {% /callout %}
- A PlanetScale database — If you haven't created a database, refer to our PlanetScale quickstart guide to get started
- A Netlify account
- A project deployed to Netlify — If you're just poking around and don't already have an application to deploy, you can use our Next.js + PlanetScale sample
-
In your PlanetScale dashboard, click on the database you want to connect to.
-
Click "Connect".
-
Select the framework you're using from the "Connect with" dropdown. This will give you the exact environment variable names you need for your selected framework. If your framework is not listed, choose "General".
-
If the password is blurred, click "New password" to generate new credentials.
-
Keep this page open, as you'll need to copy these to Netlify momentarily.
- Go to your Netlify dashboard.
- Click on your Netlify project.
- Click "Site settings".
- Click "Build & deploy," then "Environment".
- Click "Edit variable".
- Click "New variable" and copy each value from your PlanetScale dashboard into a new environment variable in Netlify. Once you're done with one, click "Add" and continue to the next, if applicable.
For example, if you're using Prisma, your connection string will look similar to this:
DATABASE_URL='mysql://xxxxxxxxx:************@xxxxxxxxxx.us-east-3.psdb.cloud/my-database?sslaccept=strict'
{% callout %}
Your environment variable name will be the same in your application's code. We used DATABASE_URL
as an example, but this can be given a different name.
{% /callout %}
In Netlify, you'll set it as follows:
- Key =
DATABASE_URL
- Value =
mysql://xxxxxxxxx:************@xxxxxxxxxx.us-east-3.psdb.cloud/my-database?sslaccept=strict
Note: The credentials are blurred for the example, but when you paste them in, use the actual values.
After you have saved, you will need to rebuild the site with the new environment variable.
Learn more about how PlanetScale allows you to make non-blocking schema changes to your database tables without locking or causing downtime for production databases.