docker mysql container installation notes

Basic Steps for MySQL Server Deployment with Docker

1 Find a suitable mysql image and select the appropriate version

docker search -f stars=3 -f is-official=true mysql--find tag is mysql, stars greater than 3 official images

2 downloads

docker pull mysql:5.7

3 run

(1)docker run -d --name mysql01 mysql:5.7

It means that the log (docker logs mysql01) cannot be started normally, and the specified parameters need to be passed in during runtime.

错误提示:database is uninitialized and password option is not specified

  You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

         (2)docker run -d -e MYSQL_ROOT_PASSWORD=password --name mysql01 mysql:5.7

4 View log

docker logs mysql01

5 Check the operation

docker ps

6 Access the mysql container

docker exec –it mysql01 bash

7 Create a new user

mysql> CREATE USER 'jack'@'localhost' IDENTIFIED BY 'pwd123456';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'jack'@'localhost' WITH GRANT OPTION;

mysql> CREATE USER 'jack'@'%' IDENTIFIED BY 'pwd123456';

mysql> GRANT ALL PRIVILEGES ON *.* TO 'jack'@'%'

    ->WITH GRANT OPTION;

 

Mysql configuration and data content mount volume

 

Key: The mapping of the file system on the Host to the files in the docker container

1 Create a custom directory on the host where the user stores configuration and data for the mapping of the corresponding files in the docker mysql container

for example:

host directory

mysql docker container directory

/root/Software/docker/mysql/config/my.cnf

/etc/my.cnf

/root/Software/docker/mysql/data

/ var / lib / mysql

Indicates that the newly created my.cnf file under the host needs initial content

my.cnf:

[mysqld]

user=mysql

2 run

docker run -d -p 3307:3307 -v=/root/Software/docker/mysql/config/my.cnf:/etc/my.cnf -v=/root/Software/docker/mysql/data:/var/lib/mysql  -e MYSQL_ROOT_PASSWORD=password --name mysql01 mysql:5.7

 

2 bash Enter the mysql01 docker container, log in to mysql to view the default character set

> docker exec -it mysql01 bash

>mysql –uroot –p

......

>show variables like ‘%char%’;

Description: Display as the lanti character set

 

3 Modify the mysql character set to utf-8, complete by modifying my.cnf

my.cnf:

 

[mysqld]

user=mysql

character-set-server=utf8

[client]

default-character-set=utf8

[mysql]

default-character-set=utf8

 

4 Delete the current container

>docker stop mysql01

>docker rm mysql01

5 Restart a new container

docker run -d -p 3307:3307 -v=/root/Software/docker/mysql/config/my.cnf:/etc/my.cnf -v=/root/Software/docker/mysql/data:/var/lib/mysql  -e MYSQL_ROOT_PASSWORD=password --name mysql01 mysql:5.7

6 Check the character set. At this time, the previously modified character set utf-8 is used by default

Description: The configuration is shared. Purpose: After the container is deleted, the data file will also be deleted. Mounting can realize data persistence and sharing.

 

References:

Mysql official website: https://dev.mysql.com/doc/refman/5.7/en/docker-mysql-more-topics.html

Learning group graphite documentation: https://shimo.im/docs/anrlYMFEYloN52c8/

Xmind documentation: Basic commands for docker

Docker command documentation: https://docs.docker.com/engine/reference/commandline

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324577576&siteId=291194637