Uses the official docker images from MySQL team

Steps

  • Start the database server
docker run --rm --name=mysql -e MYSQL_ROOT_PASSWORD=<secret> -e MYSQL_DATABASE=<database_name> -p 3306:3306 -d mysql:latest

# example
docker run --rm --name=mysql -e MYSQL_ROOT_PASSWORD=change-me-later -e MYSQL_DATABASE=test -p 3306:3306 -d mysql:latest
  • Options
docker run
 --rm # remove container when exits
 --name=mysql # name of the container
 -e MYSQL_ROOT_PASSWORD=<secret> # set the database password
 -e MYSQL_DATABASE=<database_name> # set the database name
 -p 3306:3306  # port forward 
 -v $PWD/db/:/docker-entrypoint-initdb.d/ # volume mount database init scripts
 -d mysql:latest # use latest version of the image
  • View the logs
docker logs mysql
  • Stop the database server
docker stop mysql