How to Run Queries in a Dockerized MariaDB Container Using CLI?

You can use the docker exec command (with relevant parameters) to access a dockerized MariaDB container via the command-line interface (CLI):

docker exec -it <container_name> mariadb -u <username> -p

This will allow you to execute commands inside a running MariaDB container.

You can replace the <container_name> with the name (or id) of your MariaDB container. Similarly, <username> should be replaced with the desired username for database access. By not specifying a value for the password with the -p flag, it triggers a prompt for you to enter the password when running the command.

For example, if your container name is "my-mariadb", and your username is "admin", the command would be:

docker exec -it my-mariadb mariadb -u admin -p

After executing this command, you will be prompted to enter the password. Once you provide the correct password, you should gain access to the MariaDB command-line interface where you can execute queries and interact with the database.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.