Skip to content

Instantly share code, notes, and snippets.

@kuya-joe
Forked from iamstoick/import.md
Last active May 22, 2023 00:06
Show Gist options
  • Save kuya-joe/3a3c56d894105e4caba791a83923a53f to your computer and use it in GitHub Desktop.
Save kuya-joe/3a3c56d894105e4caba791a83923a53f 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. Use -P/--port to specify the port if your exposed port of your docker mysql service is different.

  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.

Note: If you have problems with inserting records with timestamps with NULL or incorrect date values, try adding SET SQL_MODE='' first before importing.

Done

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