Report this

What is the reason for this report?

How to query a DO-managed MySQL database from a DO-hosted Nextjs app

Posted on June 21, 2024

I have a managed MySQL database which I like to query directly from a Nextjs app which is hosted as DigitalOcean app. In my local development environment I can query the database directly and get the desired results, however, when I push the app to DigitalOcean apps the query in question fails. Most likely, I have not configured the environment properly. I have configured environment variables for DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, and DB_NAME for which I used the values given in the managed database section. Moreover, I have added the app to the trusted sources for the database. In another attempt I also uploaded the SSL certificate and configured an environment variable for it. This also did not work. In the Nextjs app I use mysql2/promise to create the connection and next’s NextApiRequest and NextApiResponse as handler.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.