Search code examples
mysqlnode.jssslssl-certificateplanetscale

How do I connect to a MySQL database server running on PlanetScale with SSL from node.js on localhost?


I'm trying to connect to the MySQL server on PlanetScale, but can't as it requires SSL.

Here's their doc for that, but it's unclear what it says. https://planetscale.com/docs/concepts/secure-connections

Here's the connection URL: DATABASE_URL='mysql://co30rXXXXXXX:[email protected]/restaurant?ssl={"rejectUnauthorized":true}'

Here's what I see from my terminal when I run yarn run migration-run

yarn run v1.22.18 $ npx prisma migrate dev Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma Datasource "db": MySQL database "restaurant" at "hoqx0XXXXX.us-east-4.psdb.cloud:3306"

Error: Migration engine error: unknown error: Code: UNAVAILABLE server does not allow insecure connections, client must use SSL/TLS

error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Is there anyone who has tried to connect to PlanetScale DB from Node.js on localhost? I have tried some other suggestions from Stackoverflow, but don't seem to work.


Solution

  • ?ssl={"rejectUnauthorized":false}&sslcert=/etc/ssl/certs/ca-certificates.crt

    Adding these params at the end of the connection link, the issue has been fixed. :)