prisma: Error P1001 Can't reach database server at AWS RDS (MySQL)

Bug description

I am trying to migrate my models to an AWS RDS (MySQL) database, but I am encountering this error:

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "dbname" at "hostname.rds.amazonaws.com:3306"

MySQL database dbname created at hostname.rds.amazonaws.com:3306

Error: P1001

Can't reach database server at `hostname.rds.amazonaws.com`:`3306`

How to reproduce

Steps to reproduce the behavior:

  1. Run npm install prisma --save-dev
  2. Run prisma init and write a model
  3. Run prisma migrate dev --name m1 --preview-feature

Expected behavior

I expect it to create a database table with Prisma Migrate. It does create the database, but not the table.

Prisma information

// .env

DATABASE_URL=mysql://username:password@hostname.rds.amazonaws.com:3306/dbname

// .schema.prisma

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

generator client {
  provider = "prisma-client-js"
}

model ModelName {
  id                 Int               @default(autoincrement()) @id
  createdAt          DateTime          @default(now())
}

Environment & setup

  • OS: Mac OS
  • Database: MySQL
  • Node.js version: v14.5.0
  • Prisma version:
prisma               : 2.16.1
@prisma/client       : 2.16.1
Current platform     : darwin
Query Engine         : query-engine 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 8b74ad57aaf2cc6c155f382a18a8e3ba95aceb03 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio               : 0.346.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 30 (10 by maintainers)

Most upvoted comments

I found the problem, this was due to the AWS RDS server latency is high (in different region than my location). See https://www.prisma.io/docs/concepts/database-connectors/mysql#arguments

Solution: Add ?connect_timeout=30&pool_timeout=30&socket_timeout=30 (or higher seconds) to DATABASE_URL

Does it help when you add ?connect_timeout=30 add the end of your connection string? (or &connect_timeout=30 if you already have a ? query parameter)?

PS C:\Users\Sidharth shukla\Desktop\nextecommerce-admin> npx prisma db push Environment variables loaded from .env Prisma schema loaded from prisma\schema.prisma Datasource “db”: MySQL database “ecommerce” at “aws.connect.psdb.cloud”

Error: P1001: Can’t reach database server at aws.connect.psdb.cloud:3306

Please make sure your database server is running at aws.connect.psdb.cloud:3306.

how can i resolve this issue? continously comming in my code base???

@janpio everything is working well with the SSL, thanks for your reply!

SSL should work. You will need to download the root certificate from here for AWS as they self sign their certs: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html

Regarding comment related to port, the machine running Prisma shouldn’t be blocked and should be able to make connections to the RDS instance.

Hello. There isn’t an update. You can close this issue though since no one else seems to have this problem. I’ll update the thread if anything changes. Thank you 😃

Any update on this @sunnysid3up? Many people are using RDS and similar databases in their Prisma projects, and it is working perfectly fine for them.

@pantharshit00 I’d request that since there are several timeouts, to make error messages like:

  • Connect timeout exceeded (5 seconds)
  • Pool timeout exceeded (5 seconds)
  • Socket timeout exceeded (5 seconds)

to make the clue and next action clearer, and make error messages more unique for googling. Instead of just “Can’t reach…” which has multiple causes.

If I had read “Connect timeout exceeded (5 seconds)” at first try, I would already have thought that hey maybe it needs longer timeout since I’m connecting from Indonesia to Bahrain.

Also because Prisma has different timeout values than standard mysql CLI, that’s why it’s more confusing when testing because “I can connect using mysql just fine, so it’s not the firewall…” I do feel 5 second timeout values make sense when deploying web apps, since something is probably wrong when production DB server unreachable before that time.

Note: I don’t know if this is @sunnysid3up 's issue… but I do feel many other people have hit the same problem as me, as it’s quite easy to reproduce by using:

  • a far enough datacenter
  • a “not-so-awesome” ISP 😉

Hi, I just ran the command again and can confirm Primsa did create the database, but not the tables.

Can you confirm again that running prisma migrate dev --name m1 --preview-feature really creates the database, but not the tables? That does not really make sense to me as that should happen using the same database connection - and the error message you reported points to it not being able to create such a connection to the database.

If this is indeed the case, we have some weird debugging in front of us.