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</your_password>
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</your_password>
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></your_password>
On Windows, use the following command:
docker exec -it test-mysql mysql -uroot -p<your_password> --protocol=tcp</your_password>
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!

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 managing Kubernetes deployments, focusing on creation, updates, scaling, monitoring, and automation using various tools and best practices.

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.

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.


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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
