目录
安装mysql5.7 docker镜像
1.拉取官方mysql5.7镜像
docker pull mysql:5.7
查看镜像
docker images
2.创建mysql容器
在本地创建mysql的映射目录
cd /usr/local/
mkdir -p mysql5.7/data mysql5.7/logs mysql5.7/conf
没及时截图,弄个mysql5.7a代替后续做mysql主从吧!
在conf中创建 *.cnf 文件(叫什么都行)
我创建的my.cnf
需要事前准备好对应的文件 /usr/local/mysql5.7/conf/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, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# 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, version 2.0, 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
然后创建容器,将数据,日志,配置文件映射到本机
sudo docker run --name mysql_master --restart always --privileged=true -p 3306:3306 -v /usr/local/mysql5.7/conf/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -v /usr/local/mysql5.7/data:/var/lib/mysql -e MYSQL_USER="root" -e MYSQL_PASSWORD="root" -e MYSQL_ROOT_PASSWORD="root" -d mysql:5.7
-d: 后台运行容器
-p 将容器的端口映射到本机的端口
-v 将主机目录挂载到容器的目录
-e 设置参数
启动mysql
docker start mysql
发现刚才创建的data文件夹下多了许多文件
连接mysql,至此安装成功