Last time I wrote a MySQL installation tutorial “Yo! Latest Centos install the latest MySQL”, someone told me that it is very convenient to see others using docker to create a database.

How to use Docker to pull mysql

Install the docker

Update the yum!

yum update
Copy the code

Install the required package yum-utils device-mapper

yum install -y yum-utils device-mapper-persistent-data lvm2
Copy the code

Set the yum source to Ali Cloud

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Copy the code

Install the docker

yum install docker-ce docker-ce-cli containerd.io
Copy the code

(Try to add ‘–skip-broken’ to skip uninstallable packages or ‘–nobest’ to use not only best candidate packages)

There will be an error in this, reinstall tape — noBest

yum install docker-ce docker-ce-cli containerd.io --nobest
Copy the code

Then use docker -v to check out the docker version.

Mysql installation

After installing Docker, the next step is to install mysql.

Docker is very simple to deploy mysql, a direct command docker pull mysql ok.

If you want to specify the version, use docker pull mysql:5.7. If you do not specify the version, you will default to deploy the latest mysql, which will pull a mysql image.

Docker pull mysql: 5.7Copy the code

Above we pulled a mysql5.7 image and used it to create a container named gou_mysql. (If you are not sure, you can check it out.)

Docker run -di --name=gou_mysql -p 3389:3306 -e MYSQL_ROOT_PASSWORD=12345 mysql:5.7Copy the code

This command creates a container with name mysql, host port 3389, database port 3306, password 12345, from the mirror mysql5.7.

docker exec -it gou_mysql /bin/bash
Copy the code

Execute the container and use mysql-uroot -p12345 to log in to mysql.