Docker installs mysql5.7 and mounts configuration file data and logs

Tip : This is my personal IT resource website, you can go in and have a look

Now that docker is used more and more, let’s sort out the process of installing mysql with docker today. Generally, we use docker to install applications. It is best to mount some important files of the application to the host, so that we can compare it when viewing Convenient, no need to enter the container to view. If all the files are in the container, once the container is deleted, all the files will not exist. So today, when we install mysql with docker, we will use the mysql configuration file my.cnf and the mysql data. And logs are mounted on the host.

Download the mysql5.7 image

docker pull mysql:5.7

Insert picture description here

Use the command to view the mirror

docker images

Insert picture description here

Create three folders on the host

mkdir -p /data/mysql/conf && mkdir -p /data/mysql/data && mkdir -p /data/mysql/log

Insert picture description here

Enter the conf directory to create the my.cnf file

[mysqld]
user=mysql
character-set-server=utf8
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
expire_logs_days=7
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=1000
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

Create a mysql container and mount the directory

docker run --name mysql -p 3306:3306 -v /data/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /data/mysql/data:/var/lib/mysql -v /data/mysql/log:/var/log/mysql -e MYSQL_ROOT_PASSWORD=root --restart=always -d mysql:5.7

Check if the container is created successfully

docker ps

Insert picture description here

Use NAVICAT remote connection

Insert picture description here

end

So far, using docker to create a mysql container is successful!
Insert picture description here

This is one of the learning websites that I think is good. It is quite comprehensive. If everyone can finish the study, it is guaranteed to find a good job. Click here to check it out!

Guess you like

Origin blog.csdn.net/weixin_45345374/article/details/109069467