0

Project architecture

enter image description here


Background

Trying to connect a DB to my NextJS project. Decided to use https://www.mockaroo.com/ to generate mock DB. Then used the Planetscale browser console to create the table and insert the values with the SQL generated by mockaroo.

Successfully have a table in Planetscale

enter image description here


Problem

When doing npx prisma studio

ERROR

Message: Error in Prisma Client request: 

Invalid `prisma.mOCK_DATA.findMany()` invocation:

Can't reach database server at `us-east.connect.psdb.cloud`:`3306`

Please make sure your database server is running at `us-east.connect.psdb.cloud`:`3306`.

When doing npx prisma db pull

ERROR

Prisma schema loaded from prisma\schema.prisma
Environment variables loaded from .env
Datasource "db": MySQL database "MydbName" at "us-east.connect.psdb.cloud:3306"

✖ Introspecting based on datasource defined in prisma\schema.prisma

Error: P1001

Please make sure your database server is running at `us-east.connect.psdb.cloud`:`3306`.

scheme.prisma

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["referentialIntegrity"]
}

datasource db {
  provider = "mysql"
  url = env("DATABASE_URL")
  referentialIntegrity = "prisma"
}

.env

DATABASE_URL="mysql://{username}:{password}@us-east.connect.psdb.cloud:3306/MydbName"

Summary

I cannot connect to the Planetscale DB from my NextJS project without an ERROR connecting. I have researched this issue online and found people with the issue. But applying their changes did not fix anything i.e. https://github.com/prisma/prisma/issues/5132. For instance I tried appending ?ssl_mode=require&sslcert==us-east-1-bundle.pem to the DATABASE_URL but no changes.

I will attempt this fix soon: How do I connect to a server with SSL from node.js on localhost?

Shadow
  • 33,525
  • 10
  • 51
  • 64
Crunchy
  • 186
  • 10
  • How are you selecting the connection string from PlanetScale dashboard? Are you selecting Prisma as a method or Node.js as a method while getting the connection string? – Nurul Sundarani Nov 22 '22 at 11:58
  • Did you solve the issue? – DreamBold Dec 08 '22 at 20:10
  • 1
    @DreamBold No I never solved it. It worked on a different network on a different computer. I am certain it is a firewall issue on the network and not planetscale. – Crunchy Dec 14 '22 at 20:16
  • https://stackoverflow.com/questions/73455318/how-do-i-connect-to-a-mysql-database-server-with-ssl-from-node-js-on-localhost Would this help? – DreamBold Dec 14 '22 at 22:22
  • 1
    @DreamBold I have decided to just use Microsoft Sql Server so I am no longer working with Planetscale. But thank you. – Crunchy Dec 15 '22 at 21:21

0 Answers0