1.安装mysql5.7 docker镜像:

docker pull mysql:5.7

2.查看镜像库:

docker images

3. 在本地创建mysql的映射目录 

mkdir -p /root/mysql/data  /root/mysql/conf  /root/mysql/logs

 4.在/root/mysql/conf中创建  mysqld.cnf文件,并添加配置文件内容

cd   /root/mysql/conf
vi   mysqld.cnf
[client]
default-character-set=utf8
 
[mysql]
default-character-set=utf8
 
[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
#log-error      = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address   = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_names=1
 
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
 
max_connections = 1000

 

5.创建容器,将数据,日志,配置文件映射到本机

 

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