web123456

Installing mysql in a docker container on centos7

1. First in a centos7 virtual machinedockerThe specific installation procedure refers to the
/engine/install/centos/

docker installationUpon completion, the container in which themysqlContainer installation, in fact, the mysql installed in this is again equivalent to a small linux. using thedocker commandsPull the mysql image online, you can select the corresponding version in the process of pulling, for example, you can also pull mysql:8.0

sudo docker pull mysql:5.7 

Once the image pull is complete, use the appropriate docker commands to see if the image was pulled successfully.

sudo docker images

Run against the pulled image and set it up accordingly

  1. docker run -p 3306:3306 --name mysql \
  2. -v /mydata/mysql/log:/var/log/mysql \
  3. -v /mydata/mysql/data:/var/lib/mysql \
  4. -v /mydata/mysql/conf:/etc/mysql \
  5. -e MYSQL_ROOT_PASSWORD=root \
  6. -d mysql:5.7

Parameter description

-p 3306:3306 Maps the container's port 3306 to the host's port 3306

-v /mydata/mysql/log:/var/log/mysql \ Mount the configuration folder to the host computer
-v /mydata/mysql/data:/var/lib/mysql \ Mount the log folder to the host computer
-v /mydata/mysql/conf:/etc/mysql \ Mount the configuration folder to the host computer

-e MYSQL_ROOT_PASSWORD=root \ Initialize root user password

Use the appropriate commands to view the image after it has run successfully

sudo docker ps 

After the mysql container in the docker container is successfully running, you can add a new file to thewindowsTo test whether mysql can be connected successfully, enter the ip address of the linux client and the corresponding information.

Stop all containers in docker using the command

docker stop $(docker ps -a -q)

Deleting containers from docker images by container's id

docker rmi <image id>

Delete all images in docker

  1. docker rmi $(docker images -q)

Look inside the container

docker exec -it mysql  /bin/bash

configuration file

  1. [client]
  2. default-character-set=utf8
  3. [mysql]
  4. default-character-set=utf8
  5. [mysqld]
  6. init_connect='SET collation_connection = utf8_unicode_ci'
  7. init_connect='SET NAMES utf8'
  8. character-set-server=utf8
  9. collation-server=utf8_unicode_ci
  10. skip-character-set-client-handshake
  11. skip-name-resolve