zoukankan      html  css  js  c++  java
  • docker安装mysql

    1. 获取mysql镜像

    docker search mysql 
    docker pull msyql:5.7

    mkdir -p /docker/mysql
    cd /docker/mysql

    2. 配置启动命令

    cat <<EOF > start.sh
    #!/bin/bash
    docker run 
    --name mysql -p 3306:3306 
    -v /docker/mysql/conf:/etc/mysql/conf.d 
    -v /docker/mysql/logs:/logs 
    -v /docker/mysql/data:/var/lib/mysql 
    -–privileged=true 
    -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
    EOF

    3. 设置访问权限

    docker exec -it mysql /bin/bash
    mysql -uroot -p
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION
    FLUSH PRIVILEGES

    docker-compose 安装mysql

    1.  安装docker-compose

    curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

    2. 编写docker-compose.yml
    cd /docker/mysql

    cat <<EOF > docker-compose.yml

    version: '3.0'

    services:
      mysql57:
        container_name: mysql57
        image: mysql:5.7
        #command:
        #build:
        # context: .
        # dockerfile: Dockerfile
        ports:
          - "3306:3306"
        privileged: true
        restart: always
        networks:
          - mybridge
        volumes:
          - data:/var/lib/mysql
          - "./conf:/etc/mysql/conf.d"
          - "./logs:/logs"
        environment:
          MYSQL_DATABASE: "test"
          MYSQL_ROOT_PASSWORD: "123456"
        logging:
          driver: "json-file"
          options:
            max-size: "5g"

    networks:
      mybridge:
        driver: bridge

    volumes:
      data:

    EOF

    3. 执行docker-compose

    docker-compose up -d

    备份数据库

    [root@docker mysql]# docker exec mysql sh -c 'exec mysqldump --all-databases -uroot -p"123456" '> /mysql/all_databases.sql
  • 相关阅读:
    黄聪:DEDECMS织梦 真正的随机文章的调用方法
    黄聪:Apache 301重定向中RewriteCond规则参数介绍(转)
    [阅读笔记]fsnotify源码阅读
    [阅读笔记]Go语言并发之美
    NUMA的取舍
    Web服务器那些招
    PHP执行批量mysql语句
    gotour练习解答
    mysql多个TimeStamp设置
    mysql那些招
  • 原文地址:https://www.cnblogs.com/ray-mmss/p/10622884.html
Copyright © 2011-2022 走看看