The MySQL data source connector connects Prisma to a MySQL database server.
To connect to a MySQL database server, you need to configure a datasource
block in your schema file:
datasource mysql {
provider = "mysql"
url = env("MYSQL_URL")
}
// ... the file should also contain a data model definition and (optionally) generators
The fields passed to the datasource
block are:
provider
: Specifies themysql
data source connector.url
: Specifies the connection string for the MySQL database server. In this case, we're using an environment variable to provide the connection string.
Find more information on the datasource
fields here.
The MySQL connector maps the scalar types from the data model to native column types as follows:
Data model | MySQL |
---|---|
String |
TEXT |
Boolean |
BOOLEAN |
Int |
INT |
Float |
FLOAT |
Datetime |
TIMESTAMP |
MySQL offers two styles of connection strings:
- Key-value string:
{user:'user', host:'localhost', schema:'world'}
- Connection URI:
mysql://user@localhost:3333
See the official documentation for details.
host
: The IP address/domain of your database server, e.g.localhost
.port
: The port on which your database server listens, e.g.5432
.database
: The name of the database.user
: The database user, e.g.admin
.password
: The password for the database user.ssl
: Whether or not your database server uses SSL.connection_limit
(coming soon): The connection limit specifies the maximum number of simultaneous connections that Prisma might have open to your database. Default:1
.