prisma: Error P1010 when running `npx prisma migrate dev` with mysql

Bug description

npx prisma migrate dev throws a P1010 error User "prisma" was denied access on the database "timetracking".

The user however is correctly set up, i have no problems connecting to the db when using dbeaver. Only prisma migrate is acting strange.

How to reproduce

  1. Run npx prisma migrate dev in the project folder

Expected behavior

To be able to run npx prisma migrate devwithout P1010 error when the user is having all the right permissions.

Prisma information

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

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

model User {
    id          String        @id @default(uuid())
    name        String
    createdAt   DateTime      @default(now())
    updatedAt   DateTime      @updatedAt
    TrackedTime TrackedTime[]
}

model TrackedTime {
    id     String    @id @default(uuid())
    start  DateTime  @default(now())
    end    DateTime?
    user   User      @relation(fields: [userId], references: [id])
    userId String
}

DATABASE_URL=mysql://prisma:test@localhost:3306/timetracking

Environment & setup

  • OS: Ubuntu 22.04 Kernel 6.0.9
  • Database: MySQL running as docker container, port 3306 exposed, v8.0.31 or v5.7.40 (makes no difference)
  • Node.js version: 18.12.1

Prisma Version

prisma                  : 4.6.1
@prisma/client          : 4.6.1
Current platform        : debian-openssl-3.0.x
Query Engine (Node-API) : libquery-engine 694eea289a8462c80264df36757e4fdc129b1b32 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-3.0.x.so.node)
Migration Engine        : migration-engine-cli 694eea289a8462c80264df36757e4fdc129b1b32 (at node_modules/@prisma/engines/migration-engine-debian-openssl-3.0.x)
Introspection Engine    : introspection-core 694eea289a8462c80264df36757e4fdc129b1b32 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-3.0.x)
Format Binary           : prisma-fmt 694eea289a8462c80264df36757e4fdc129b1b32 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-3.0.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.6.1-3.694eea289a8462c80264df36757e4fdc129b1b32
Default Engines Hash    : 694eea289a8462c80264df36757e4fdc129b1b32
Studio                  : 0.476.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 16

Most upvoted comments

Encountered this issue, fixed by proper permissions.

For mysql user must have CREATE, ALTER, DROP, REFERENCES ON *.*

ref: prisma docs

I was able to fix the issue by explicitly creating a shadow_db and defining its URL in the the prisma.schema datasource block:

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

🤷‍♂️

my app has the same problem on ubuntu 2204

I had same issue but im using Postgres I just have to change username in connection string on ‘user’

Hello,

I’m experiencing the same issue with :

prisma                  : 5.1.1
@prisma/client          : 5.1.1
Current platform        : linux-musl-openssl-3.0.x
Query Engine (Node-API) : libquery-engine 6a3747c37ff169c90047725a05a6ef02e32ac97e (at node_modules/.pnpm/@prisma+engines@5.1.1/node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node)
Schema Engine           : schema-engine-cli 6a3747c37ff169c90047725a05a6ef02e32ac97e (at node_modules/.pnpm/@prisma+engines@5.1.1/node_modules/@prisma/engines/schema-engine-linux-musl-openssl-3.0.x)
Schema Wasm             : @prisma/prisma-schema-wasm 5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e
Default Engines Hash    : 6a3747c37ff169c90047725a05a6ef02e32ac97e
Studio                  : 0.492.0

npx prisma db push works fine, Prisma client can connect to the database read & write, but npx prisma migrate dev doesn’t work:

npx prisma migrate dev --name init
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "abcd" at "mariadb:3306"

Error: P1010
User `xxxx` was denied access on the database `abcd`

It also can create database, as they are visible in adminer : CleanShot 2023-08-21 at 18 06 00

I’m using this docker container for mariadb :

FROM mariadb:11.0.2

ADD ./scripts/initdb.sh /docker-entrypoint-initdb.d/initdb.sh

initdb.sh does :

mariadb -uroot -p"$MYSQL_ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS $DB_PRISMA;"
mariadb -uroot -p"$MYSQL_ROOT_PASSWORD" -e "GRANT ALL PRIVILEGES ON $DB_PRISMA* TO $DB_USER@'%' IDENTIFIED BY '$DB_PASSWORD';"

mariadb -uroot -p"$MYSQL_ROOT_PASSWORD" -e "GRANT CREATE ON *.* TO $DB_USER@'%';"
mariadb -uroot -p"$MYSQL_ROOT_PASSWORD" -e "FLUSH PRIVILEGES;"

Hope it helps!

This is a totaly different issue, you have problems with openssl. Maybe try upgrading your openssl version and if that doesn’t help open a seperate issue.

update openssl 3.0 on ubuntu 22.04 ,it is running .thank you very much.