Docker has become the most popular application containerization technology. It runs on any platform (Linux, Windows, Mac), thus greatly simplifying application deployment and management. Docker can containerize not only the application itself, but also dependent services, such as databases. In this article, we will discuss how to install and configure a MySQL database using Docker.
docker pull mysql
This will download the latest version of the MySQL Docker image.
docker run --name test-mysql -e MYSQL_ROOT_PASSWORD=<your_password> -p 3306:3306 -d mysql
The above command will create a new container from the MySQL Docker image, named test-mysql. The parameter "-e MYSQL_ROOT_PASSWORD=
If you are running Docker on a Windows system, you need to run the following command:
docker run --name test-mysql -e MYSQL_ROOT_PASSWORD=<your_password> -p 3306:3306 -d mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
Unlike Linux/Mac, Windows does not support modifying the character set and sorting method inside the container before running the MySQL container. , so these options need to be specified when running the container.
docker ps
You should see that the test-mysql container is included in the returned results information, indicating that the container has been successfully run.
docker exec -it test-mysql mysql -uroot -p<your_password>
On Windows, use the following command:
docker exec -it test-mysql mysql -uroot -p<your_password> --protocol=tcp
After running the above command, you will enter the MySQL command line interface. This means you have successfully installed the MySQL Docker container.
Summary
Docker makes it easier to install and manage MySQL. In this article, we explain how to download the MySQL Docker image from Docker Hub and create a MySQL container. We also provide more detailed installation steps for Windows users. With these steps, you should have successfully learned how to check Docker installation of MySQL.
The above is the detailed content of How to use Docker to install and configure a MySQL database. For more information, please follow other related articles on the PHP Chinese website!