Using docker to install MySQL in Linux Environment



A few days ago, when I was running a project, the background couldn’t get up. After reading the error information, I found that my MySQL version was too old to use. Because I used xampp, and the version followed the xampp version. The solution given on the Internet is to run the command: MySQL_ Upgrade – U root – P updates the MySQL library, but I can’t use it here. At the suggestion of my friends, I decided to install docker.
Using docker to install MySQL in Linux Environment


Linux Installation docker has a detailed tutorial on the Internet, which will not be repeated here. If necessary, please see the installation of Ubuntu docker
After installing docker, if thesudodocker run hello-worldappear
Using docker to install MySQL in Linux Environment
Indicates that docker is successfully installed.
Next, we use docker to install mysql.
1. We can use it first

sudo docker search mysql

To see the available versions, but we chose the stable version 5.7 as our installation
2. Pull MySQL image

docker pull mysql:5.7

If the download speed is slow, it is recommended to replace the domestic source
First modify or add new ones/etc/docker/daemon.jsonDocument, content changed to

"registry-mirrors": [""]

Save exit, if the download is still slow, it is recommended to change a few sources to try. This article provides a lot of domestic original.
After saving, restart the docker service.

service docker restart

Pull MySQL again.
After installation, we pass thesudo docker imagesTo see if MySQL is installed correctly
3. Run MySQL container
After installation, we use

docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7

To run the MySQL container
–Name MySQL test is our container name
-P 3306: 3306 is the mapping service port 3306 to the host computer port 3306. When we visit, we access port 3306.
MYSQL_ ROOT_ Password = 123456 the root password we set
MySQL: 5.7 set the MySQL version to be started.
After success, we usesudo docker ps -aCommand to see if the startup was successful.
Using docker to install MySQL in Linux Environment
4. Enter
We use

sudo docker exec -it mysql-test bash

Enter the container we just created, and then go through the

mysql -uroot -p123456

Enter MySQL environment command
Using docker to install MySQL in Linux Environment
Pay attention to the change in the beginning to judge whether the command is in effect.
Finally, we use the


Command to allow root to log in from any location.
Using docker to install MySQL in Linux Environment
Finally, open our Navicat test
Using docker to install MySQL in Linux Environment
The connection was successful.


We passedsudo docker ps -aTo view the started container, you can use thesudo docker stop XXXTo stop andsudo docker rm XXXDelete the container. XXX is the ID value of the container
Using docker to install MySQL in Linux Environment
It is worth noting that our container here is a virtual machine. After we shut it down, we also keep it in the state. Instead of a series of tedious commands after power on, it can be used directly. If you delete and rebuild, your data table will disappear.


When using docker for the first time, I still don’t know the power of docker, so I will experience it carefully in the future.
Thank you for your careful guidance in this process.

This article is written by Zhao Zhiqiang, the development team of Hebei Industrial University

Recommended Today

CentOS install Chinese Fonts

preface When we encounter some Chinese display garbled problems, it may be because the server does not install Chinese fonts install 1. View system fontsBefore starting the installation, we first check the installed fonts in the system. To view the installed fonts in the system, we can use thefc-listIf there is no command in the […]