How to restore a .sql.gz dump on a Docker MySQL instance?

I have a dump which was taken from a machine on which Docker is NOT installed. The format is .sql.gz – my question is how do I restore this on my Docker MySQL instance?

Able to access MySQL from command line:

  • Dockerfile COPY instruction failing?
  • Pass “volume-driver” option to kubernetes pod
  • Log file configuration using Crate.IO database docker image
  • How to programmatically monitor if a docker container exited?
  • Load balance docker containers in Mesos cluster with HAproxy
  • How to convert a systemctl command to supervisord command
  • docker run -it --link first-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
    

    NOT able to restore the dump using this:

    docker exec -i first-mysql mysql -uroot -ppassword < db_dump.sql

  • What does #(nop) mean in docker history?
  • Docker localhost IP
  • docker's VOLUME isn't mounting host files
  • Installing docker in client mode
  • how force deleting docker image affects existing containers using it
  • Make PHP and Nginx Docker images work together
  • 2 Solutions collect form web for “How to restore a .sql.gz dump on a Docker MySQL instance?”

    Basic syntax is:

    gunzip dump.sql.gz
    docker exec -i container_name mysql -uroot -proot < dump.sql
    

    Or copy dunp.sql into a volume go into the conatainer and start mysql there

    docker exec -ti container_name bash
    mysql < /volume_dir/dump.sql
    

    The rest in mysql syntax.

    1. Because logging in from root wasn’t an issue, log into MySQL using root.
    2. Create another user with all the privileges, a kind of equivalent to root.
    3. Flush privieleges.

    docker exec -i container_name mysql -uloader -ploader < dump.sql

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.