This is how to load a sql dump file from directory to a mysql database in a container.
Make sure you have a volume set up with the directory you keep your sql files in. In my case, I have a directory called “/data/raw” that I keep all my csv and sql files in for loading and dumping.
docker command
sudo docker run --name some-mariadb -v /data/mysql:/var/lib/mysql -v/data/raw:/data/raw-e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:latest
or…
docker-compose yaml file.
mariadb:
image: mariadb
container_name: some-mariadb
environment:
- "MYSQL_ROOT_PASSWORD:my-secret-pw"
volumes:
- /data/mysql:/var/lib/mysql
- /data/raw:/data/raw
ports:
- 3306:3306
I change the directory to my /data/raw directory on my linux box that I’m running the container on.
To load a file into mysql/mariadb, open mysql from the command line:
docker exec -it some-mariadb mysql -u root -pmy-secret-pw my-database
and then…
MariaDB []> source /data/raw/dump-file_data.sql
I use the same method for postgres