docker 安装mysql8.0

第一步

docker pull mysql

第二步

在宿主机创建放置mysql的配置文件的目录,和数据目录,然后创建my.cnf配置文件

mkdir /usr/local/mysql_conf

mkdir /usr/local/mysql_data

vi /usr/local/mysql_conf/my.cnf

 附上mysql8.0默认的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/

第三步 

执行创建容器命令

docker run -d --name mysql -v /usr/local/mysql_conf/my.cnf:/etc/mysql/my.cnf -v /usr/local/mysql_data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

-v 挂载宿主机目录和 docker容器中的目录

-d 后台运行

-p 映射容器端口号和宿主机端口号

-e 环境参数

----------------------------------分割线-----------------------------------------------------------------------

这里说个坑

之前博主用不挂载宿主机目录的方式来部署mysql 然后通过

docker exec -it mysql bash 

进入容器内部的

/etc/mysql 

目录来修改my.cnf  

注:docker 容器内部默认没有文本编辑器(后面有介绍为容器安装vim)

通过 这种方式来配置mysql的配置有一个致命的缺点 ,my.cnf改错了会导致容器无法启动然后无法通过命令行的方式来修该mysql配置文件来恢复容器,相当扯淡!!!

另外容器中默认 是没有安装vi 或者vim的编辑器的 

先用 docker exec -it xxxx bash 进入容器命令行 然后

apt update //更新容器软件列表

apt install vim //安装vim编辑器  注:软件源中并没有vi编辑器 却有更强大的vim编辑器 用法相同

这样就可以在容器中用编辑器修改文本文件了相当好用!! 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值