Run MySQL database without installing anything

Sometimes we need to inspect a database dump. With MySQL it's easy to run a database locally without even installing the MySQL Server. Using Docker, run the official MySQL image and mount your SQL dump file(s) to a special directory named /docker-entrypoint-initdb.d/ inside the container.

All versions of the official MySQL Docker image have this nice feature: they run SQL files stored in the designated directory when you first launch a container. You may store as many SQL files as you want in this directory, they will be executed in alphabetical order. When you remove the container, the databases will be destroyed too. Great for speed and keeping your computer clean. The only thing you need is this Docker Compose configuration:

  
  version: "3"
  services:
    mysql:
      image: "mysql"
      environment:
        - MYSQL_ROOT_PASSWORD=secretpassword
        - MYSQL_DATABASE=cats
      volumes:
        - ./cats.sql:/docker-entrypoint-initdb.d/cats.sql:ro
      ports:
        - "3306:3306"
  

Then run docker-compose up