Skip to content

Instantly share code, notes, and snippets.

@shadyueh
Forked from iamstoick/import.md
Created June 21, 2021 17:10
Show Gist options
  • Save shadyueh/98cd6f8d925991351e5bf8e303864d76 to your computer and use it in GitHub Desktop.
Save shadyueh/98cd6f8d925991351e5bf8e303864d76 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

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