Aiven MySQL and Koyeb
Aiven for MySQL (opens in a new tab) allows you to get a fully managed MySQL database deployed in the cloud of your choice in a few minutes. Aiven takes care of everything for you including installing security patches, upgrades, automatic backups, and allows you to scale your MySQL databases up or down as needed.
This guide explains how to connect an Aiven managed MySQL database to an application running on Koyeb. To successfully follow this documentation, you will need to have:
- A Koyeb account (opens in a new tab) to deploy the application. You can optionally install the Koyeb CLI to deploy the application from the command line.
- An Aiven account (opens in a new tab) to deploy the Aiven MySQL database.
The application that connects to the Aiven managed 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 Aiven managed MySQL database running and want to quickly preview how to connect your 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 Aiven
To create an Aiven managed MySQL database, sign in to your Aiven account (opens in a new tab).
On the Aiven control panel, click the Create Service button to provision a database and access the service creation page.
- Select MySQL as the service you want to create.
- Choose the Cloud Provider where your Aiven database will run. You can choose between AWS, GCP, Azure, DigitalOcean, and UpCloud. For this guide, we use Google Cloud.
- Pick the Region to run the database in. Here, we selected google-europe-west3 (Frankfurt) as our compute will be deployed in this region on Koyeb.
- Select the service Plan. Different plans are available depending on what resources and features you need. For this guide, we use the Hobbyist plan.
- Give your service a name, e.g.
When you are done configuring your database, click the Create service button. Your database will be provisioned.
From your Aiven MySQL service page, click the Copy button icon on the right side of the Service URI field. The connection string should be similar to the following:
Save it in a safe place, we will need it in the next step to connect our application to the database.
You can deploy on Koyeb using the control panel or via the Koyeb CLI.
- Create a new Koyeb App.
github.com/koyeb/example-express-prismaas the GitHub repository to deploy and keep the default branch as
npm run mysql:initas the Build command.
- Add a
DATABASE_URLenvironment variable to tell the application how to connect to the Aiven MySQL database. Give the environment variable the name
DATABASE_URLand enter the connection string from earlier as the value.
- Name your service, for instance
- Click the Deploy button.
A Koyeb App and Service will be created. Your application will be built and deployed to Koyeb. Once the build has finished, you will be able to access your application running on Koyeb by clicking the URL ending with
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
To delete the example application and the Aiven MySQL database and avoid incurring any charges, follow these steps: