• 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
  • 相关阅读:
    WPF添加动画过渡效果
    【Numpy总结】强烈推荐。超实用Numpy学习目录,一篇学会Numpy
    bootstrap和application的区别
    MySQL存储引擎
    06 ts扩展知识
    java项目开发jsp编程web鸽谱信息系统myeclipse开发Mysql数据库计算机网页
    [车联网安全自学篇] 五十四. Android安全之剪贴板+键盘缓存+UI界面+自动截屏敏感信息挖掘
    【自然语言处理(NLP)】基于Transformer的英文自动文摘
    java计算机毕业设计在线学习跟踪系统前台源程序+mysql+系统+lw文档+远程调试
    王道计算机考研 操作系统学习笔记 + 完整思维导图篇章五: IO管理
  • 原文地址:https://blog.csdn.net/weixin_45550881/article/details/128156993