# Import from MySQL

Import an existing MySQL database into Prisma Postgres, then use it with Prisma ORM.

Move an existing MySQL database into Prisma Postgres, then connect Prisma ORM to it.

## Prerequisites

You need:

- the connection URL for the MySQL database you are importing from
- a Prisma Data Platform account
- `pgloader`
- Node.js 24 or newer

## 1. Create a Prisma Postgres database

Create a Prisma Postgres database from Console or with the CLI. Copy the direct connection string. You will use it for the import and for `DATABASE_URL`.

## 2. Create a pgloader config

Create `config.load`:

```text title="config.load"
LOAD DATABASE
    FROM mysql://USER:PASSWORD@HOST:PORT/DATABASE
    INTO postgres://USER:PASSWORD@db.prisma.io:5432/?sslmode=require

WITH quote identifiers,
     include drop,
     create tables,
     create indexes,
     reset sequences

ALTER SCHEMA 'DATABASE' RENAME TO 'public';
```

## 3. Import into Prisma Postgres

Run pgloader:

```shell
pgloader config.load
```

## 4. Add Prisma ORM

From your app root, initialize Prisma ORM:

:::code-group
```bash title="bun"
bunx prisma@latest orm init
```

```bash title="pnpm"
pnpm dlx prisma@latest orm init
```

```bash title="yarn"
yarn dlx prisma@latest orm init
```

```bash title="npm"
npx prisma@latest orm init
```
:::

Choose PostgreSQL, set `DATABASE_URL` to the Prisma Postgres connection string, then infer and emit the contract:

:::code-group
```bash title="bun"
bunx prisma contract infer --output ./prisma/contract.prisma
bunx prisma contract emit
bunx prisma db sign
```

```bash title="pnpm"
pnpm prisma contract infer --output ./prisma/contract.prisma
pnpm prisma contract emit
pnpm prisma db sign
```

```bash title="yarn"
yarn prisma contract infer --output ./prisma/contract.prisma
yarn prisma contract emit
yarn prisma db sign
```

```bash title="npm"
npx prisma contract infer --output ./prisma/contract.prisma
npx prisma contract emit
npx prisma db sign
```
:::

## Next steps

- Review table and column names in the inferred contract.
- Use [Add Prisma ORM to an existing PostgreSQL database](/guides/prisma-orm-add-to-existing-project-postgresql) for the first Prisma ORM query.
- Use the [full Prisma Postgres MySQL import guide](/guides/prisma-postgres-import-from-existing-database-mysql) for deeper migration details.

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
