原创

docker部署启动mysql挂载数据目录配置文件目录

1.docker-composer启动

写docker-composer.yml文件

version: '3'
services:
    dkmyqsl56:
        environment:
            MYSQL_ROOT_PASSWORD: "123456"
            MYSQL_USER: 'root'
            MYSQL_PASS: '123456'
        image: "mysql:5.6"
        restart: always
        volumes:
            - "${PWD}/data:/var/lib/mysql"
            - "${PWD}/conf/my.cnf:/etc/my.cnf"
        ports:
            - "3301:3306"

2.docker命令启动

docker run --privileged=true\
 -v ${PWD}/conf/my.cnf:/etc/my.cnf\
 -v ${PWD}/data:/var/lib/mysql\
 -e MYSQL_USER=root\
 -e MYSQL_ROOT_PASSWORD=123456\
 -p 3301:3306\
 -d f7ba8643e01a

相关准备
1.挂载了配置文件,和数据挂载目录,创建data目录
2.创建conf目录已经创建 my.cnf文件 可以自己去官网下载一个

3.my.cnf

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql

#!includedir /etc/mysql/conf.d/
#!includedir /etc/mysql/mysql.conf.d/
#log-error      = /var/log/mysql/error.log
# Disabling symbolic-links is recommended to prevent assorted security risks
正文到此结束
本文目录