Connection URLs

Prisma ORM needs a connection URL to be able to connect to your database, e.g. when sending queries with Prisma Client or when changing the database schema with Prisma Migrate.

The connection URL is provided via the url field of a datasource block in your Prisma schema. It generally consists of the following components (except for SQLite):

  • User: The name of your database user
  • Password: The password for your database user
  • Host: The IP or domain name of the machine where your database server is running
  • Port: The port on which your database server is running
  • Database name: The name of the database you want to use

Make sure you have this information at hand when getting started with Prisma ORM. If you don't have a database server running yet, you can either use a local SQLite database file (see the Quickstart) or .

Format

The format of the connection URL depends on the database connector you're using. Prisma ORM generally supports the standard formats for each database. You can find out more about the connection URL of your database on the dedicated docs page:

Special characters

For MySQL, PostgreSQL and CockroachDB you must in any part of your connection URL - including passwords. For example, p@$$w0rd becomes p%40%24%24w0rd.

For Microsoft SQL Server, you must escape special characters in any part of your connection string.

Examples

Here are examples for the connection URLs of the databases Prisma ORM supports:

PostgreSQL

schema.prisma
1datasource db {
2 provider = "postgresql"
3 url = "postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
4}

MySQL

schema.prisma
1datasource db {
2 provider = "mysql"
3 url = "mysql://janedoe:mypassword@localhost:3306/mydb"
4}

Microsoft SQL Server

schema.prisma
1datasource db {
2 provider = "sqlserver"
3 url = "sqlserver://localhost:1433;initial catalog=sample;user=sa;password=mypassword;"
4}

SQLite

schema.prisma
1datasource db {
2 provider = "sqlite"
3 url = "file:./dev.db"
4}

CockroachDB

schema.prisma
1datasource db {
2 provider = "cockroachdb"
3 url = "postgresql://janedoe:mypassword@localhost:26257/mydb?schema=public"
4}

MongoDB

schema.prisma
1datasource db {
2 provider = "mongodb"
3 url = "mongodb+srv://root:<password>@cluster0.ab1cd.mongodb.net/myDatabase?retryWrites=true&w=majority"
4}

.env

You can also provide the connection URL as an environment variable:

schema.prisma
1datasource db {
2 provider = "postgresql"
3 url = env("DATABASE_URL")
4}

You can then either set the environment variable in your terminal or by providing a file named .env. This will automatically be picked up by the Prisma CLI.

Prisma ORM reads the connection URL from the dotenv file in the following situations:

  • When it updates the schema during build time
  • When it connects to the database during run time
DATABASE_URL=postgresql://janedoe:mypassword@localhost:5432/mydb