4

I have a docker container with mariadb, and have created a database my_db in it (through an external script in a different container). How can I run SQL queries on my_db now from the command line? I just want to do

select * from my_table

from the terminal that is running the container.

2 Answers 2

3

Easiest way is to exec into the container and execute the query using the mysql client, given the clients installed.

docker exec -it CONTAINER_NAME mysql -p -e 'QUERY' DB_NAME
Sign up to request clarification or add additional context in comments.

Comments

1

If you have the commandline tool installed in the app container,

mysql -h 192.168.1.7 -u admin -pxyz -P 10202

This allows for the docker instance to be on another machine (192...) and with a special port (-P ...), etc. (I have multiple docker containers; that one is for MariaDB 10.2.2.)

2 Comments

What is -pxyz for?
-p, no space, is how you can put the password on the commandline.

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.