Skip to content

Instantly share code, notes, and snippets.

@minademian
Forked from geraldvillorente/import.md
Created November 19, 2021 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minademian/226f9278b2675107d67274c179f7c542 to your computer and use it in GitHub Desktop.
Save minademian/226f9278b2675107d67274c179f7c542 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