Sometimes I want access to a fresh database to test out something I'm working on. I just want to be able to spin it up quickly, run my tests, and then clean it up without too much hassle. I've found the fastest way for me to do that is with Docker Compose and this docker-compose.yml file:

version: "3.7"

    image: mysql:8.0.22
    command: --default-authentication-plugin=mysql_native_password
      MYSQL_DATABASE: "uber_cool_db"
      MYSQL_USER: "even_cooler_username"
      MYSQL_PASSWORD: "the_coolest_password"
      MYSQL_ROOT_PASSWORD: "basic_password"
      - "3305:3306"

From there, I can spin up the database with:

docker-compose up -d

Connect to it with:

mysql -h -u root -pbasic_password -P 3305 uber_cool_db -A

And clean it up with:

docker-compose down

Full documentation for the MySQL docker image is here, but this post exists so that I can just copy-paste this docker-compose.yml file whenever I need it without having to reference the documentation every time.