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.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hey!
What is the exact error that you get when you try to deploy your app to the App Platform?
I recently answered a similar quesiton regarding
mysql2/promise
and a managed MySQL cluster:The issue from the discussion above was fixed by actually storing the CA certificate as a file instead of passing it as a string:
What you could do is to add a command to the app that creates the certificate file upon runtime, such as
echo $MYSQL_CA_CERT > ca_cert.cert && <original run command>
. App Platform requires the original run time command to start the app upon runtime.Then you can reference that file in the connection string, eg:
Let me know how it goes!
- Bobby