Skip to content

Instantly share code, notes, and snippets.

@vanquyet94
Forked from iamstoick/import.md
Created May 26, 2022 10:08
Show Gist options
  • Save vanquyet94/eae57a45dd9ad16eae309b4334b8df17 to your computer and use it in GitHub Desktop.
Save vanquyet94/eae57a45dd9ad16eae309b4334b8df17 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

@vanquyet94
Copy link
Author

Update: docker exec -i container_name mysql -uroot -ppassword db_name < db.sql

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