MySQL
MySQL is a popular open-source relational database management system. This guide will walk you through how to use MySQL with Spin.
Installation
To install MySQL, you will be prompted to include the MySQL service on install. You simply just need to select it.
What Spin does for you
When you install MySQL, Spin will set up a dedicated "MySQL" service for you with persistent volumes so you do not lose data when updating your container.
Default Configuration
The database uses the official MySQL image. The default configuration allows us to:
- ✅ Quickly set up a database service with the exact version of our choice
- ✅ Automatically create databases, users, and passwords (defined by the
environment:
variables in thedocker-compose.*.yml
files)
⚠️ Special Connection Notes
Since the database is running in a container, you will need to connect to the database using the container name. For example, if you have a Laravel application, you would use the following in your .env
file:
Example .env File
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laraveluser
DB_PASSWORD=laravelpassword
From your development workstation, we expose the database service on port 3306
. This is the default port for MySQL and MariaDB. This means you can use localhost
and 3306
to connect to the database.
Usage
When you run spin up
, the MySQL container will create our database and start the MySQL service.