Docker Compose 安装 MySQL

1. 新建docker-compose.yml

version: '3.1'

services:
    mysql:
        container_name: mysql
        image: mysql:8
        command: --default-authentication-plugin=mysql_native_password
        ports:
            - '3306:3306'
        volumes:
            - "/opt/mysql/data:/var/lib/mysql"
            - "/opt/mysql/conf.d:/etc/mysql/conf.d"
        restart: always
        environment:
            TZ: Asia/Shanghai
            MYSQL_ROOT_PASSWORD: 请输入root密码
            MYSQL_DATABASE: 请输入数据库名称
            MYSQL_USER: 请输入用户名
            MYSQL_PASSWORD: 请输入用户密码
            MYSQL_ROOT_HOST: '%'

2. 创建并启动容器

docker-compose up -d

未经允许不得转载:君子如兰 » Docker Compose 安装 MySQL

赞 (0)