docs/1.7/04-Reference/05-Prisma-Servers-&-DBs/02-Database-Connectors/02-MySQL.md
To connect your Prisma server to a MySQL database, you need to use the MySQL connector. The connector needs to be specified in the docker-compose.yml file that's the foundation for your Prisma server:
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.7
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
managementApiSecret: my-server-secret-123
port: 4466
databases:
default:
connector: mysql
active: true
host: db
port: 3306
user: root
password: prisma
db:
image: mysql
restart: always
environment:
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: prisma
You can setup a new Prisma server that connects to a MySQL database using the Prisma CLI (requires Docker):
prisma init hello-worldhello-world directory: cd hello-worlddocker-compose up -dprisma deploy to deploy your Prisma APIIf you have used previous versions of the Prisma CLI with Docker, you need to clear your Docker setup before running docker-compose up -d, otherwise you might run into the following error message:
ERROR: for mysql_prisma_1 Cannot start service prisma: driver failed programming external connectivity on endpoint mysql_prisma_Creating mysql_db_1 ... done
ERROR: for prisma Cannot start service prisma: driver failed programming external connectivity on endpoint mysql_prisma_1 (b9aa3375c9374b77bab447b3777d1e5a7d78e0081106699b637065e6db4a5a88): Bind for 0.0.0.0:4466 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.
You can clear your Docker setup using the following commands:
docker kill $(docker ps -aq)
docker rm $(docker ps -aq)
Note: If you're using
fishor some other shell, you might need to adjust the commands accordingly.