| title | Relational databases | ||||||
|---|---|---|---|---|---|---|---|
| metaTitle | Add Prisma ORM to an existing project using JavaScript and MySQL (15 min) | ||||||
| metaDescription | Learn how to add Prisma ORM to an existing Node.js project by connecting it to your MySQL database and generating a Prisma Client for database access. | ||||||
| hide_table_of_contents | true | ||||||
| langSwitcher |
|
||||||
| dbSwitcher |
|
||||||
| sidebar_custom_props |
|
||||||
| sidebar_class_name | hidden-sidebar | ||||||
| pagination_next | getting-started/setup-prisma/add-to-existing-project/relational-databases/connect-your-database-node-mysql | ||||||
| slugSwitch | /getting-started/setup-prisma/add-to-existing-project/relational-databases- |
Learn how to add Prisma ORM to an existing Node.js or TypeScript project by connecting it to your database and generating a Prisma Client for database access. The following tutorial introduces you to the Prisma CLI, Prisma Client, and Prisma Introspection.
:::tip
If you're migrating to Prisma ORM from another ORM, see our Migrate from TypeORM or Migrate from Sequelize migration guides.
:::
In order to successfully complete this guide, you need:
- an existing Node.js project with a
package.json - Node.js installed on your machine (see system requirements for officially supported versions)
- a MySQL database server running and a database with at least one table
See System requirements for exact version requirements.
Make sure you have your database connection URL (that includes your authentication credentials) at hand! If you don't have a database server running and just want to explore Prisma ORM, check out the Quickstart.
As a first step, navigate into your project directory that contains the package.json file.
Next, add the Prisma CLI as a development dependency to your project:
npm install prisma --save-dev
:::note
If your project contains multiple directories with package.json files (e.g., frontend, backend, etc.), note that Prisma ORM is specifically designed for use in the API/backend layer. To set up Prisma, navigate to the appropriate backend directory containing the relevant package.json file and configure Prisma there.
:::
You can now invoke the Prisma CLI by prefixing it with npx:
npx prisma
See installation instructions to learn how to install Prisma ORM using a different package manager.
Next, set up your Prisma ORM project by creating your Prisma schema file template with the following command:
npx prisma init
This command does two things:
- creates a new directory called
prismathat contains a file calledschema.prisma, which contains the Prisma schema with your database connection variable and schema models - creates the
.envfile in the root directory of the project, which is used for defining environment variables (such as your database connection)