Error: P1001 - Can't reach database server
See original GitHub issueBug description
I executed npx prisma migrate dev --name init
and I encounter below error.
✅Create database
❌Create tables
I have tried to connect the database server in GUI and java program, so I can confirm the database server is working.
prisma:loadEnv project root found at /Users/abc/Desktop/code/abc-server/package.json +0ms
prisma:tryLoadEnv Environment variables loaded from /Users/abc/Desktop/code/abc-server/.env +0ms
Environment variables loaded from .env
prisma:engines binaries to download libquery-engine, migration-engine, introspection-engine, prisma-fmt +0ms
Prisma schema loaded from prisma/schema.prisma
prisma:getConfig Using CLI Query Engine (Node-API Library) at: /Users/abc/Desktop/code/abc-server/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node +0ms
Datasource "db": MySQL database "abcdb" at "abc.mysql.rds.aliyuncs.com:3306"
prisma:getDMMF Using CLI Query Engine (Node-API) at: /Users/abc/Desktop/code/abc-server/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node +0ms
prisma:getConfig Using CLI Query Engine (Node-API Library) at: /Users/abc/Desktop/code/abc-server/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node +33ms
prisma:getConfig Using CLI Query Engine (Node-API Library) at: /Users/abc/Desktop/code/abc-server/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node +2ms
MySQL database abcdb created at abc.mysql.rds.aliyuncs.com:3306
prisma:migrateEngine:rpc starting migration engine with binary: /Users/abc/Desktop/code/abc-server/node_modules/@prisma/engines/migration-engine-darwin +0ms
prisma:migrateEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"devDiagnostic","params":{"migrationsDirectoryPath":"/Users/abc/Desktop/code/abc-server/prisma/migrations"}} +8ms
prisma:migrateEngine:stderr {"timestamp":"2022-01-04T13:14:26.979787Z","level":"INFO","fields":{"message":"Starting migration engine RPC server","git_hash":"8746e055198f517658c08a0c426c7eec87f5a85f"},"target":"migration_engine"} +0ms
prisma:migrateEngine:rpc {
prisma:migrateEngine:rpc jsonrpc: '2.0',
prisma:migrateEngine:rpc error: {
prisma:migrateEngine:rpc code: 4466,
prisma:migrateEngine:rpc message: 'An error happened. Check the data field for details.',
prisma:migrateEngine:rpc data: {
prisma:migrateEngine:rpc is_panic: false,
prisma:migrateEngine:rpc message: "Can't reach database server at `abc.mysql.rds.aliyuncs.com`:`3306`\n" +
prisma:migrateEngine:rpc '\n' +
prisma:migrateEngine:rpc 'Please make sure your database server is running at `abc.mysql.rds.aliyuncs.com`:`3306`.',
prisma:migrateEngine:rpc meta: [Object],
prisma:migrateEngine:rpc error_code: 'P1001'
prisma:migrateEngine:rpc }
prisma:migrateEngine:rpc },
prisma:migrateEngine:rpc id: 1
prisma:migrateEngine:rpc } +5s
Error: Error: P1001
Can't reach database server at `abc.mysql.rds.aliyuncs.com`:`3306`
Please make sure your database server is running at `abc.mysql.rds.aliyuncs.com`:`3306`.
at Object.<anonymous> (/Users/abc/Desktop/code/abc-server/node_modules/prisma/build/index.js:101665:25)
at Object.handleResponse (/Users/abc/Desktop/code/abc-server/node_modules/prisma/build/index.js:101536:36)
at LineStream3.<anonymous> (/Users/abc/Desktop/code/abc-server/node_modules/prisma/build/index.js:101625:16)
at LineStream3.emit (events.js:315:20)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:284:9)
at LineStream3.Readable.push (_stream_readable.js:223:10)
at LineStream3.Transform.push (_stream_transform.js:166:32)
at LineStream3._pushBuffer (/Users/abc/Desktop/code/abc-server/node_modules/prisma/build/index.js:101422:17)
at LineStream3._transform (/Users/abc/Desktop/code/abc-server/node_modules/prisma/build/index.js:101416:8)
How to reproduce
npx prisma migrate dev --name init
Expected behavior
No response
Prisma information
schema.prisma
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
generator nexusPrisma {
provider = "nexus-prisma"
}
datasource db {
provider = "mysql"
url = env("MYSQL_ABCDB_URL")
referentialIntegrity = "prisma"
}
model User {
id Int @id @default(autoincrement())
name String
posts Post[]
profile Profile?
}
model Profile {
id Int @id @default(autoincrement())
biograpy String // Intentional typo!
userId Int
user User @relation(fields: [userId], references: [id])
}
model Post {
id Int @id @default(autoincrement())
title String
published Boolean @default(true)
content String
authorId Int
author User @relation(fields: [authorId], references: [id])
categories Category[]
}
model Category {
id Int @id @default(autoincrement())
name String
posts Post[]
@@unique([name])
}
.env
MYSQL_ABCDB_URL="mysql://user:password@abc.mysql.rds.aliyuncs.com:3306/abcdb?serverTimezone=Asia/Hong_Kong&useUnicode=true&characterEncoding=UTF-8"
Environment & setup
- OS: Mac OS
- Database: MySQL
- Node.js version: v14.15.1
Prisma Version
prisma : 3.7.0
@prisma/client : 3.7.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 8746e055198f517658c08a0c426c7eec87f5a85f
Studio : 0.445.0
Preview Features : referentialIntegrity
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Error P1001 Can't reach database server at AWS RDS (MySQL)
Try connecting to the database using cli or a gui first.
Read more >Error: P1001: Can't reach database server at `localhost`:`5200`
Localhost and the mapped port are used when connecting from the host machine. You're connecting from another container on the bridge network and ......
Read more >Error: P1001: Can't reach database server at `dpg ...
I was developing an API using Express Js, Prisma is the ORM am using and I decided to use Render DB and connect...
Read more >Help wanted: Error: P1001: Can't reach database server at "db ...
Hi all, I'm starting a new project and going through the docs to use supabase + prisma + React but despite following the...
Read more >Error message reference - Prisma
Prisma Client, Migrate, Introspection error message reference. ... P1001. "Can't reach database server at {database_host} : {database_port} Please make sure ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry I didn’t mention that the database can only be connected via internal network.
I tried to expose the database to public for testing and access it via public endpoint. The command
npx prisma migrate dev --name init
works well.However, the same error occurred when I execute the command with internal endpoint, but I did connect the database successfully through internal endpoint in DBeaver and java program.
Is your EC2 instance accessible from your local machine? Do other database clients or UIs work? Often connecting locally is slower, so you might want to increase the timeout.