skip to Main Content

I got a MariaDB database dump from a colleague, and he asked me to run it in a docker container.
So i executed the following:

docker pull mariadb:10.4.26

then created the container

docker run --name test_smdb -e MYSQL_ROOT_PASSWORD=<some_password> -p 3306:3306 -d mariadb:10.4.26

then connected to the container:

docker exec -it test_smdb mariadb --user root -p<some_password>

and created a database in it from the mariadb prompt:

MariaDB [(none)]> CREATE DATABASE smdb_dev;

So far, so good. But when i tried to import the dump into it via this command:

docker exec -i test_smdb mariadb -uroot -p<some_password> --force < C:smdb-dev.sql

i get a lot of lines like
ERROR 1046 (3D000) at line 22: No database selected.

So i am not sure what exactly is the issue?

  1. Should i define a database, in which the dump should be imported? If yes – how exactly, because i look at different pages, like:
    https://hub.docker.com/_/mariadb, especially this:
$ docker exec -i some-mariadb sh -c 'exec mariadb -uroot -p"$MARIADB_ROOT_PASSWORD"' < /some/path/on/your/host/all-databases.sql

and i see no database mentioned here.

Or
2) The colleague has not created the dump in the correct way?

2

Answers


  1. I do not use mariadb in a docker environment at my place, but I do use mariadb on a linux machine so it should be really similar.

    You said you used this command :

    docker exec -i test_smdb mariadb -uroot -p<some_password> --force < C:smdb-dev.sql

    If we breakthrough it :

    • docker exec -i test_smdb docker stuff where you ask docker to execute the following command on the test_smdb container (or close to it, I’m not a docker daily user).
    • mariadb -uroot -p<password> --force here is the interesting part. You ask your shell to open mariadb and login as root with then given password with an extra flag --force. But you never specify which database should be overridden.

    In my gist, again for mariadb outside docker but I really think it should be the same, I’ve the following command mariadb -uusername -p<password> <DB_NAME> < /path/to/file.sql

    So I would try something like :
    docker exec -i test_smdb mariadb -uroot -p<some_password> smdb_dev --force < C:smdb-dev.sql

    Login or Signup to reply.
  2. Below command should work I believe

    docker exec -i test_smdb sh -c "exec mariadb -uroot -pPASSWORD smdb_dev" < /some/path/on/your/host/all-databases.sql
    

    Reference: Import local database to remote host Docker container

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search