zoukankan      html  css  js  c++  java
  • Docker-compose部署MySQL

    目录结构

    /Mysql             # Mysql应用文件夹
      docker-compose.yml      # docker compose脚本文件
      init.sql                  # mysql初始sql文件
     /conf            # 配置文件夹
       my.cnf          # 配置文件          
      /db             # 数据库文件         

    docker-compose.yml

    version: '3'
    services:
        mysql:
            network_mode: "bridge"
            environment:
                MYSQL_ROOT_PASSWORD: "yourpassword"
                MYSQL_USER: 'test'
                MYSQL_PASS: 'yourpassword'
            image: "mysql:5.5"
            restart: always
            volumes:
                - "./db:/var/lib/mysql"
                - "./conf/my.cnf:/etc/my.cnf"
                - "./init:/docker-entrypoint-initdb.d/"
            ports:
                - "3306:3306"

    my.cnf

    [mysqld]
    user=mysql
    default-storage-engine=INNODB
    character-set-server=utf8
    [client]
    default-character-set=utf8
    [mysql]
    default-character-set=utf8

    init.sql

    create database test;
    use test;
    create table user
    (
    id int auto_increment primary key,
    username varchar(64) unique not null,
    email varchar(120) unique not null,
    password_hash varchar(128) not null,
    avatar varchar(128) not null
    );
    insert into user values(1, "zhangsan","test12345@qq.com","passwd","avaterpath");
    insert into user values(2, "lisi","12345test@qq.com","passwd","avaterpath");

    运行

    docker-compose up -d
  • 相关阅读:
    js触摸屏案例
    Docker
    Docker 镜像加速
    Docker 命令大全
    linux gpasswd
    Docker基础教程
    PHP输出毫秒时间戳
    PHP Variable handling 函数
    Partition Array by Odd and Even
    Median
  • 原文地址:https://www.cnblogs.com/-wenli/p/14233010.html
Copyright © 2011-2022 走看看