question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: P1001: Can't reach database server (PlanetScale)

See original GitHub issue

Bug description

Hello, I’m trying out Prisma with PlanetScale and it’s not going so smooth because I’m getting the following error after typing npx prisma migrate dev:

  prisma:loadEnv project root found at /home/goodwin/flaut-nextjs/package.json +0ms
  prisma:tryLoadEnv Environment variables loaded from /home/goodwin/flaut-nextjs/.env +0ms
[dotenv][DEBUG] did not match key and value when parsing line 1: # Created by Vercel CLI
[dotenv][DEBUG] did not match key and value when parsing line 19: 
Environment variables loaded from .env
  prisma:engines using Node API: false +0ms
  prisma:engines binaries to download query-engine, migration-engine, introspection-engine, prisma-fmt +0ms
Prisma schema loaded from prisma/schema.prisma
  prisma:getConfig Using Query Engine Binary at: /home/goodwin/flaut-nextjs/node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x +0ms
Datasource "db": MySQL database "flautru" at "g8oms8wlmppb.eu-west-2.psdb.cloud:3306"

  prisma:getDMMF Using Query Engine Binary at: /home/goodwin/flaut-nextjs/node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x +0ms
  prisma:getConfig Using Query Engine Binary at: /home/goodwin/flaut-nextjs/node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x +34ms
  prisma:getConfig Using Query Engine Binary at: /home/goodwin/flaut-nextjs/node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x +11ms
Error: Error: P1001: Can't reach database server at `g8oms8wlmppb.eu-west-2.psdb.cloud`:`3306`

Please make sure your database server is running at `g8oms8wlmppb.eu-west-2.psdb.cloud`:`3306`.
    at ensureDatabaseExists (/home/goodwin/flaut-nextjs/node_modules/prisma/build/index.js:63712:13)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async _MigrateDev.parse (/home/goodwin/flaut-nextjs/node_modules/prisma/build/index.js:65680:28)
    at async main (/home/goodwin/flaut-nextjs/node_modules/prisma/build/index.js:105366:18)

I’ve been able to establish successfull connection with both MySQL Workbench GUI for Windows and mysql-client for Linux (WSL2). The only thing that is failing is Prisma.

How to reproduce

  1. Create database via app.planetscale.com
  2. Create new branch out of main
  3. Copy both main and dev branch URLs to Vercel
  4. Execute vercel pull to get env variables (so now prod URL points to main and shadow database URL points to dev branch)
  5. Make schema changes to schema.prisma
  6. Execute npm prisma migrate dev

Expected behavior

No response

Prisma information

Environment & setup

  • OS: Windows 10, WSL2
  • Database: PlanetScale MySQL
  • Node.js version: v12.22.1

Prisma Version

prisma               : 2.29.1
@prisma/client       : 2.29.1
Current platform     : debian-openssl-1.1.x
Query Engine         : query-engine 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/query-engine-debian-openssl-1.1.x)
Migration Engine     : migration-engine-cli 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary        : prisma-fmt 1be4cd60b89afa04b192acb1ef47758a39810f3a (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : 1be4cd60b89afa04b192acb1ef47758a39810f3a
Studio               : 0.419.0
Preview Features     : planetScaleMode, nApi

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
abriginetscommented, Aug 24, 2021

Yep, replacing /etc/pki/tls/certs/ca-bundle.crt with /etc/ssl/certs/ca-certificates.crt for local environment solved the issue. The solution for me at this point would be having four different URLs at Vercel environment variables list (two with /etc/ssl/certs/ca-certificates.crt for local and two with /etc/pki/tls/certs/ca-bundle.crt for preview and prod). Thank you for your help.

1reaction
janpiocommented, Aug 24, 2021

Thanks for the feedback, and sorry this was so confusing and required you to actually create an issue here. I opened https://github.com/prisma/prisma/issues/8890 to hopefully make the error message a bit more insightful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

prisma Error: p1001: Can't reach database server at `db ...
I had a similar issue with a Sveltekit application using Prisma and PlanetScale (MySQL) and Docker on Windows (WSL).
Read more >
Error message reference - Prisma
P1001. "Can't reach database server at {database_host} : {database_port} Please make sure your database server is running at {database_host} ...
Read more >
Error: P1001: Can't reach database server at `localhost`:`5200`
Coding example for the question Error: P1001: Can't reach database server at `localhost`:`5200`-docker.
Read more >
How to set up Next.js with Prisma and PlanetScale
We'll walk through setting up a new database, installing Prisma, defining your ... we log the error and respond with a server code...
Read more >
connecting to planetscale database from a docker ... - Fly.io
2022-06-10T12:46:22.144 app[8942000f] lhr [info] Error: P1001: Can't reach database server at qd6hc1lvteex.eu-west-3.psdb.cloud : 3306.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found