Command to create MySQL Docker image and access the MySQL command-line interface (CLI) within a running Docker container

Created at 16-Mar-2024 , By samar

In this article you will learn about to how to create a docker container named mysql-server using image mysql:latest and will learn about how to access the MySQL command-line interface (CLI) within a running Docker container named mysql-server.

First run the Docker container based on the latest version of the MySQL Docker image.

docker run --name mysql-server -p 3308:3308 -e MYSQL_ROOT_PASSWORD=password -d mysql:latest

Now run command docker exec -it mysql-server mysql -u root -p allows you to access the MySQL command-line interface (CLI) within a running Docker container named "mysql-server".

docker exec -it mysql-server mysql -u root -p

Here is the detailed information about above command.

docker exec: This is the Docker command to execute a command in a running container.

-it: Specifies that the command should be executed interactively, allowing you to interact with the container's terminal.

mysql-server: Specifies the name of the Docker container to execute the command in.

mysql: This is the MySQL CLI command that you want to execute within the container.

-u root: Specifies the MySQL user to connect as. In this case, it's the root user.

-p: Prompts for the MySQL password.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.