• mysql安装(docker)


    mkdir /opt/mysql

    vim /opt/mysql/Dockerfile

    5.7

    FROM mysql:5.7.26
    EXPOSE 3306

    8.0

    FROM mysql:latest
    EXPOSE 3306

    创建文件夹

    mkdir /opt/mysql/var/lib/mysql -p

    vim /opt/mysql/docker-compose.yml

    5.7

    version: '3.6'
    services:
      mysql: 
        image: v-mysql:5.7
        container_name: mysql
        network_mode: "host"
        build: 
          context: .
          dockerfile: Dockerfile
        environment: 
    MYSQL_ROOT_HOST: '%' MYSQL_ROOT_PASSWORD:
    "root" MYSQL_USER: 'test' MYSQL_PASS: '123456' MYSQL_ALLOW_EMPTY_PASSWORD: "no" restart: always command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M --sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO" volumes: - "./var/lib/mysql:/var/lib/mysql" - "./etc/my.cnf:/etc/my.cnf" - "./docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d/" ports: - "3306:3306"

    不用Dockerfile时

    version: '3.6'
    services:
      mysql: 
        image: mysql:5.7.26
        container_name: mysql
        network_mode: "host"
        environment: 
    MYSQL_ROOT_HOST: '%' MYSQL_ROOT_PASSWORD:
    "root" MYSQL_USER: 'test' MYSQL_PASS: '123456' MYSQL_ALLOW_EMPTY_PASSWORD: "no" restart: always command: --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M --sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO" volumes: - "./var/lib/mysql:/var/lib/mysql" - "./etc/my.cnf:/etc/my.cnf" - "./docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d/" ports: - "3306:3306"

    8.0

    version: '3.6'
    services:
      mysql: 
        image: v-mysql:8.0
        container_name: mysql
        network_mode: "host"
        build: 
          context: .
          dockerfile: Dockerfile
        environment: 
          MYSQL_ROOT_PASSWORD: "root"
          MYSQL_USER: 'test'
          MYSQL_PASS: '123456'
          MYSQL_ALLOW_EMPTY_PASSWORD: "no"
        restart: always
        command: 
          --default-authentication-plugin=mysql_native_password
          --character-set-server=utf8mb4
          --collation-server=utf8mb4_general_ci
          --explicit_defaults_for_timestamp=true
          --lower_case_table_names=1
        volumes: 
          - "./var/lib/mysql:/var/lib/mysql"
          - "./etc/my.cnf:/etc/my.cnf"
          - "./docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d/"
        ports:
          - "3306:3306"

    mysql配置文件

    mkdir /opt/mysql/etc
    vim /opt/mysql/etc/my.cnf

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

    /docker-entrypoint-initdb.d/init.sql
    sql脚本(略)

    build和启动
    cd /opt/mysql
    docker-compose build
    docker-compose up -d
    docker-compose down
    docker-compose restart

    进入容器
    docker exec -it mysql /bin/bash

  • 相关阅读:
    spring mvc常用配置
    spring data redis使用1——连接的创建
    spring session使用小记
    log4j2使用入门(一)
    com.google.common.eventbus.EventBus介绍
    使用java远程调试技术监控代码运行
    阿里云数加平台——数据同步任务调度及管理
    阿里云数加平台——BI报表使用概述和总结
    解决因block的损坏而导致hdfs启动后进入安全模式
    iOS 6 自动布局入门
  • 原文地址:https://www.cnblogs.com/wintersoft/p/11083701.html
Copyright © 2020-2023  润新知