Docker下部署安装Mysql

Docker下部署安装Mysql

1.拉取镜像

# 拉取最新版本
docker pull mysql
# 拉取指定版本号
docker pull mysql:版本号

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

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

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是默认不区分大小写的。

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

参数说明:
–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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值