docs/1.15/get-started/01-setting-up-prisma-new-database-a002.mdx
import QueryChooser from 'components/Markdown/QueryChooser' import Code from 'components/Markdown/Code'
export const meta = { title: 'Setting up Prisma', gettingStartedTitle: 'New database', position: 1, gettingStartedOrder: 2, nextText: 'Great work! 👏 Move on to learn how you can extend your data model and make changes to your Prisma API.' }
On this page, you will learn how to:
The Prisma CLI is used to deploy and manage Prisma services. You can install it using NPM:
npm install -g prisma
To use Prisma locally, you need to have Docker installed on your machine. If you don't have Docker yet, you can download the Docker Community Edition for your operating system here.
To launch a Prisma server on your machine, you need a Docker Compose file that configures the Prisma server and specifies the database it can connect to.
touch docker-compose.yml
Paste the following contents into the Docker Compose file you just created:
<Code languages={["MySQL", "PostgreSQL"]}>
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.15
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: mysql
host: mysql
port: 3306
user: root
password: prisma
migrations: true
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: prisma
volumes:
- mysql:/var/lib/mysql
volumes:
mysql: ~
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.15
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: postgres
host: postgres
port: 5432
user: prisma
password: prisma
migrations: true
postgres:
image: postgres
restart: always
environment:
POSTGRES_USER: prisma
POSTGRES_PASSWORD: prisma
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres: ~
You can switch between MySQL and PostgreSQL by using the tabs above the code block.
To start the Prisma server and launch the connected database, run the following command:
docker-compose up -d
To bootstrap the service configuration files for your first Prisma service, create a new directory and initalize it using the prisma init command:
mkdir hello-world
cd hello-world
prisma init --endpoint http://localhost:4466
The prisma init command created the minimal service configuration needed to deploy a Prisma service: prisma.yml and datamodel.graphql.
This service configuration now needs to be deployed so you can use the Prisma API of your service:
prisma deploy
The Prisma API of your service exposes CRUD and realtime operations for the User type defined in datamodel.graphql. You can explore the API in a GraphQL Playground using the following command:
prisma playground
Here are a few sample queries and mutations you can send to explore the API.
<QueryChooser titles={["Create a new User", "Query all Users", "Update a User's name", "Delete a User"]}>
mutation {
createUser(data: {
name: "Alice"
}) {
id
}
}
query {
users {
id
name
}
}
mutation {
updateUser(
where: { id: "__USER_ID__" },
data: { name: "Sarah" }
) {
id
name
}
}
mutation {
deleteUser(where: {
id: "__USER_ID__"
}) {
id
name
}
}