dockers 部署 mysql-server-5.7.41

一、 部署 Docker

1.1 安装 Docker

yum install yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

yum install docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin

1.2 设置 docker 自启

systemctl enable docker.socket --now
systemctl enable docker --now

二、 配置容器MySQL

2.1 获取 MySQL 容器

官方容器
docker pull mysql/mysql-server:5.7.41

2.2 创建相关目录

  • MySQL数据目录: mkdir -p /home/mysql-5.7.41/data
  • MySQL配置目录: mkdir -p /home/mysql-5.7.41/conf

2.3 容器编排文件

#vim docker-compose.yml
version: '3'
services:
mysql:
image: mysql/mysql-server:5.7.41
restart: always
container_name: mysql-5.7.41
environment:
MYSQL_ROOT_PASSWORD: $youpasswd
TZ: Asia/Shanghai
ports:
- 3307:3307
volumes:
- /home/mysql-5.7.41/data:/var/lib/mysql
- /home/mysql-5.7.41/conf/my.cnf:/etc/mysql/my.cnf

2.4 MySQL 配置文件

#vim /home/mysql-5.7.41/conf/my.cnf
[mysqld]
port=3307
user=mysql
default-storage-engine=INNODB
character-set-server=utf8
character-set-client-handshake=FALSE
collation-server=utf8mb4_general_ci
init_connect='SET NAMES utf8'
max_connections=1000
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4

三、 启动容器 MySQL

  • 启动
    docker-compose up -d
  • 日志
    docker logs -f mysql-5.7.41