Install / start, run, and mount MySQL5.7 on Docker

See the download document: https://hub.docker.com/r/mysql/mysql-server

1. Download the mirror

Execute command: docker pull mysql / mysql-server: 5.7

 View command: docker images

 

 

 Run MySQL background running and map to local port command: docker run -d -p 3306: 3306 --name mysql mysql / mysql-server: 5.7

 

 

 View running container: docker ps

 

 

 Monitor the output of the container: docker logs mysql

 

 

 Command to connect to mysql server: docker exec -it mysql mysql -uroot -p

The password is: docker logs mysql output the content after the password

 

 

 Reset the password of the mysql service:ALTER USER 'root'@'localhost' IDENTIFIED BY 'password'

 

 

 Create a user and grant permissions: create user 'user name' @ '%' identified by 'password';

                                      grant all privileges on *. * to 'username' @ '%' with grant option;

 

 

 

 

 

3. Set the character set encoding format

 Enter the container: docker exec -it mysql bash

cd / etc

 

 

 Install vim editor: yum install vim

 

 

 Enter the mysql configuration file: vim my.cnf

 

 

 Content after writing

[client]
#password       = your_password
port               = 3306
socket          = /data0/data/mysql.sock
default-character-set = utf8mb4

[mysql]  
default-character-set = utf8mb4

[mysqld]  
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'

port            = 3306
socket          = /data0/data/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
datadir = /data0/data

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout  

 

 

You can also configure the parameters by running the container:

The command is as follows 

docker run -d -p 3306: 3306 -e MYSQL_USER = "user name" -e MYSQL_PASSWORD = "password" -e MYSQL_ROOT_PASSWORD = "password" --name mysql mysql / mysql-server: 5.7 --character-set-server = utf8 --collation-server = utf8_general_ci

 

 

 

Docker installation mysql documentation:  https://dev.mysql.com/doc/refman/5.7/en/docker-mysql-getting-started.html

Personally suggest to configure the parameters directly by running the container

Guess you like

Origin www.cnblogs.com/vic-tory/p/12697551.html