Step-by-Step Guide to Installing MySQL Using Docker
This tutorial explains how to download the MySQL Docker image, create and run a MySQL container with volume mappings and environment variables, verify the container, connect to the database via Workbench, and access the container’s shell and host files.
First, pull the MySQL 5.7 image from Docker Hub: sudo docker pull mysql:5.7 The command downloads the image and shows progress details, confirming the image is ready for use.
Verify the downloaded image with: sudo docker images Next, create and start a MySQL container, mapping host directories for logs, data, and configuration, exposing port 3306, and setting the root password:
sudo docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7After the container starts, you can list running containers to confirm the MySQL instance is active.
Connect to the MySQL server using MySQL Workbench or any client, then verify the databases are accessible.
To enter the container’s shell for further inspection or management, run: sudo docker exec -it mysql /bin/bash Finally, on the host machine, view the mapped directories to see the persisted log, data, and configuration files:
cd /mydata/mysql
lsThis series of commands provides a complete setup for running MySQL in Docker with persistent storage and easy access for development or testing purposes.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Wukong Talks Architecture
Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
