Skip to content

Instantly share code, notes, and snippets.

@geraldvillorente
Created June 14, 2017 05:03
Show Gist options
  • Save geraldvillorente/4c60e7fdb5562f443f16ad2bbe4235ce to your computer and use it in GitHub Desktop.
Save geraldvillorente/4c60e7fdb5562f443f16ad2bbe4235ce to your computer and use it in GitHub Desktop.
How to import database in MySQL in Docker?

This is a simple way of importing MySQL database in Docker.

  1. In you Dockerfile you must have a shared folder. Shared folder is a directory in your host machine that is mounted to Docker instance.

  2. Put the exported sql file in the shared folder.

  3. Login to your Docker instance via docker exec -it DOCKER_CONTAINER_ID bin/bash.

  4. Login to MySQL via mysql -u USERNAME -p.

  5. While in MySQL CLI, create a database via create database DB_NAME;.

  6. While in MySQL CLI, use the database you just created via use DB_NAME;.

  7. While in MySQL CLI, import the sql file via source /path/to/file.sql.

Done

@still-breathing
Copy link

Thanks a lot this helped me a lot, i wish I stumbled upon it an hour ago. Kudos to you brother

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment