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:

  • Installing Docker on CentOS 6.6
  • Gitlab migrate from 6.x to 8 in docker
  • Warning: Module 'curl' already loading in Unknown on line 0 (Fix this from a custom.php.ini file)
  • Docker : Unable to resolve the name of the machine host?
  • Run OpenCv in jupyter with Docker
  • `docker run` on a remote host
  • 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

  • managing a hierarchy of docker images
  • Setting up redis with docker
  • Running nano in docker container
  • Query MySql database in Docker
  • Docker for Mac nginx example doesn't run
  • Docker doesn't persist created file
  • 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.