• Docker下部署安装Mysql


    Docker下部署安装Mysql

    1.拉取镜像

    # 拉取最新版本
    docker pull mysql
    # 拉取指定版本号
    docker pull mysql:版本号
    
    • 1
    • 2
    • 3
    • 4

    2.在宿主机创建文件夹,易于管理Mysql配置文件等(当前目录在根目录下/data下),创建mysql目录并创建conf、data目录

    mkdir -p /data/mysql && cd $_ && mkdir {conf,data}
    
    • 1

    3.创建配置文件my.cnf

    # Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     
    #
     
    # This program is free software; you can redistribute it and/or modify
     
    # it under the terms of the GNU General Public License as published by
     
    # the Free Software Foundation; version 2 of the License.
     
    #
     
    # This program is distributed in the hope that it will be useful,
     
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
     
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     
    # GNU General Public License for more details.
     
    #
     
    # You should have received a copy of the GNU General Public License
     
    # along with this program; if not, write to the Free Software
     
    # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
     
    #
     
    # The MySQL Server configuration file.
     
    #
     
    # For explanations see
     
    # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
     
    [mysqld]
     
    pid-file = /var/run/mysqld/mysqld.pid
     
    socket = /var/run/mysqld/mysqld.sock
     
    datadir = /var/lib/mysql
     
    secure-file-priv= NULL
     
    # Disabling symbolic-links is recommended to prevent assorted security risks
     
    symbolic-links=0
     
    # Custom config should go here
     
    !includedir /etc/mysql/conf.d/
     
    max_connections=1000
    wait_timeout=120
    interactive_timeout=300
     
    lower_case_table_names=1 # unix默认是0,windows默认是1,mac是2 0是区分大小写的,1是不区分的,也就是windows是默认不区分大小写的。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61

    4.创建mysql容器

    docker run --restart=always -d --name webmysql -p xxxx:3306 -v /web-data/data/mysql/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /web-data/data/mysql/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Aini.52070 mysql
    
    • 1

    参数说明:
    –restart=always :自动重启;
    -d:守护进程
    –name webmysql:修改映射的名称;
    -p xxxx:3306:端口映射,宿主机:docker下;
    -v /web-data/data/mysql/mysql/conf/my.cnf:/etc/mysql/my.cnf :宿主机地址:docker下配置
    -v /web-data/data/mysql/mysql/data:/var/lib/mysql :宿主机数据位置:docker下数据位置
    -e MYSQL_ROOT_PASSWORD=xxxx :设置密码
    mysql :docker引入的mysql名称

    5.docker下可能需要用到的命令

    # 进入docker下mysql容器
    docker exec -it webmysql /bin/bash
    
    # 查看指定容器日志
    docker logs -f --tail 查看的数量 容器id
    
    # 查看所有容器
    docker ps -a
    
    # 删除创建的容器
    docker rm 容器id
    
    # 重启容器
    docker restart 容器名/容器id
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
  • 相关阅读:
    JSON 提取器
    拖动排序与置顶的Java实现
    Java基础知识
    利用API数据接口进行市场调研的详细指南
    读书笔记-你不知道的js(中卷)
    链表合并 分数 25
    Vue2:MVVM 设计模式、Vue指令、模板语法
    音视频标签
    Nginx 相关介绍(Nginx是什么?能干嘛?)
    不可错过的效能利器「GitHub 热点速览 v.22.39」
  • 原文地址:https://blog.csdn.net/weixin_45550881/article/details/128156993