How to use Docker to install and configure a MySQL database
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.
- Download the MySQL Docker image
First, we need to download the MySQL Docker image from Docker Hub. Run the following command to download the latest version of MySQL from Docker Hub.
docker pull mysql
This will download the latest version of the MySQL Docker image.
- Create MySQL container
Once the MySQL Docker image is downloaded, we can create the MySQL container. In Linux/Mac systems, you can use the following command:
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.
- Check MySQL container status
Run the following command to check the status of 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.
- Login to the MySQL container
On Linux/Mac systems, you can log in to the MySQL container with the following command:
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article details deploying applications to Docker Swarm, covering preparation, deployment steps, and security measures during the process.

The article explains Kubernetes' pods, deployments, and services, detailing their roles in managing containerized applications. It discusses how these components enhance scalability, stability, and communication within applications.(159 characters)

The article discusses scaling applications in Kubernetes using manual scaling, HPA, VPA, and Cluster Autoscaler, and provides best practices and tools for monitoring and automating scaling.

The article discusses implementing rolling updates in Docker Swarm to update services without downtime. It covers updating services, setting update parameters, monitoring progress, and ensuring smooth updates.

Article discusses managing services in Docker Swarm, focusing on creation, scaling, monitoring, and updating without downtime.

The article discusses managing Kubernetes deployments, focusing on creation, updates, scaling, monitoring, and automation using various tools and best practices.

This article details implementing rate limiting and resource quotas in Docker. It covers CPU, memory, and I/O limits using cgroups, emphasizing best practices for preventing resource exhaustion. Network rate limiting, requiring external tools like

The article discusses strategies to optimize Docker for low-latency applications, focusing on minimizing image size, using lightweight base images, and adjusting resource allocation and network settings.
