0

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?

1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

5 Comments

Thanks, Vasanth, but when i tried to execute this, i got : mariadb: 1: Syntax error: Unterminated quoted string
I tested this in Mac and it worked fine. Looks like you are using Windows. If so, can you try hard coding the password without quotes and check once? Thank you
Depend on if the test_smdb was started with the $MARIADB_ROOT_PASSWORD set. Also the contents password is expanded by bash so if it contains quotes that could explain the error.
Thanks Vasanth, but i hardcoded the password and i faced the same issue
Got it, try replacing single-quotes with double-quotes, it should work. Got a chance to test in Windows environment and it worked for me. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.