Docker-compose 安装mysql8

1、编写docker-compose.yml文件

version: '3.8'
services:
  mysql:
    container_name: mysql8
    image: mysql:8.0.18
    restart: always
    ports:
      - 3306:3306
    privileged: true
    volumes:
      - $PWD/log:/var/log/mysql
      - $PWD/conf/my.cnf:/etc/mysql/my.cnf
      - $PWD/data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: "123456"
    command: [
        '--default-authentication-plugin=mysql_native_password',
        '--lower_case_table_names=1',
        '--character-set-server=utf8mb4',
        '--collation-server=utf8mb4_general_ci',
        '--max_connections=3000'
    ]

2、创建目录结构

mkdir conf/ data/ log/ mysql-files/
chmod -R 777 data/ log/ mysql-files/

3、编写my.cnf文件

[mysqld]
user=mysql
# 表示允许任何主机登陆MySQL
bind-address = 0.0.0.0
port=3306
default-storage-engine=INNODB
#character-set-server=utf8
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
secure-file-priv=
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4

4、启动mysql容器

docker-compose up -d
docker-compose ps
NAME      IMAGE          COMMAND                  SERVICE   CREATED        STATUS        PORTS
mysql8    mysql:8.0.18   "docker-entrypoint.s…"   mysql     26 hours ago   Up 23 hours   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp

新增账号和设置账号密码详情请见mysql8遇到的账号密码设置及登录问题

你可能感兴趣的:(docker-compose,MySQL,docker,容器,MySQL)