1、下载镜像文件
docker pull mysql:5.7
2、创建实例并启动
docker run -p 3307:3306 --name mysql-master \ -v /mydata/mysql/master/log:/var/log/mysql \ -v /mydata/mysql/master/data:/var/lib/mysql \ -v /mydata/mysql/master/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.7
参数说明
l -p 3307:3306:将容器的3306端口映射到主机的3307端口
l -v /mydata/mysql/master/conf:/etc/mysql:将配置文件夹挂在到主机
l -v /mydata/mysql/master/log:/var/log/mysql:将日志文件夹挂载到主机
l -v /mydata/mysql/master/data:/var/lib/mysql/:将配置文件夹挂载到主机
l -e MYSQL_ROOT_PASSWORD=root:初始化root用户的密码
MySQL配置
vim /mydata/mysql/conf/my.cnf [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve
查看状态
docker ps
修改配置文件后重启mysql
docker restart mysql