Docker安装MySQL5.7

第一步

新建以下目录:
mkdir -p /www/mysql/conf.d 配置目录
mkdir -p /www/mysql/datadir 数据目录
mkdir -p /www/mysql/mysql.conf.d 配置目录

第二步

在 conf.d 文件夹内新建 docker.cnf 文件

[mysqld]
skip-host-cache
skip-name-resolve

在 conf.d 文件夹内新建 mysql.cnf 文件

[mysql]

在 conf.d 文件夹内新建 mysqldump.cnf 文件

[mysqldump]
quick
quote-names
max_allowed_packet      = 16M

第三步

在 mysql.conf.d 文件夹内新建 mysqld.cnf 文件

# Copyright (c) 2014, 2016, 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
#log-error      = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address   = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

第四步

拉取镜像
docker pull mysql:5.7

第五步构建容器

docker run --name mysql --restart=always -p 3306:3306 -v /www/mysql/conf.d:/etc/mysql/conf.d -v /www/mysql/mysql.conf.d:/etc/mysql/mysql.conf.d -v /www/mysql/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=zan123456 -d mysql:5.7 


--restart 标志会检查容器的退出代码,并据此来决定是否要重启容器,默认是不会重启。
--restart的参数说明
always:无论容器的退出代码是什么,Docker都会自动重启该容器。
on-failure:只有当容器的退出代码为非0值的时候才会自动重启。另外,该参数还接受一个可选的重启次数参数,`--restart=on-fialure:5`表示当容器退出代码为非0时,Docker会尝试自动重启该容器,最多5次。

-v 容器内的 /var/lib/mysql 在宿主机上 /www/mysql/datadir 做映射  
-e MYSQL_ROOT_PASSWORD 初始密码
-p 将宿主机3306的端口映射到容器3306端口
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值