How to import an existing MySQL-Database in my MySQL-Docker Container? How to import an existing MySQL-Database in my MySQL-Docker Container? docker docker

How to import an existing MySQL-Database in my MySQL-Docker Container?


There are several methods to import. With docker exec if your contener is running:

Solution 1:

docker exec -i <id_conteneur> /usr/bin/mysql -u <fooUser> -e "CREATE DATABASE mydb"cat schema.sql | docker exec -i <id_conteneur> /usr/bin/mysql -u <fooUser> --password=<password> <database>

Solution 2:

In a bash script:

#!/bin/bash /usr/bin/mysqld_safe --skip-grant-tables &mysql -u <fooUser> -e "CREATE DATABASE mydb" mysql -u <fooUser> mydb < schema.sql

And add to your DockerFile with Run command:

ADD create_db.sh /tmp/create_db.shRUN /tmp/create_db.sh