📅  最后修改于: 2023-12-03 15:30:31.951000             🧑  作者: Mango
Docker is a popular platform for creating, deploying, and managing containerized applications. MySQL is one of the most widely used relational database management systems in the world. In this tutorial, we will show you how to use Docker to run MySQL in a container.
Before you start, you will need the following:
The first step is to pull the official MySQL image from Docker Hub using the following command:
docker pull mysql
Once the image is downloaded, you can start a new container by running the following command:
docker run -d --name=mysql-container -e MYSQL_ROOT_PASSWORD=<password> mysql
This command will start a new MySQL container in detached mode with the specified root password.
Now that your MySQL container is up and running, you can connect to it using the following command:
docker exec -it mysql-container mysql -p
This command will open a Bash shell inside the container and launch the MySQL client. You will be asked to enter the root password that you specified earlier.
Congratulations! You have successfully run MySQL in a Docker container. With Docker, you can easily create and manage isolated containers for all of your applications, including MySQL. This allows you to keep your development environment clean and streamlined, while ensuring that your applications are running in a consistent and reliable environment.