# 拉取最新版本
docker pull mysql
# 拉取指定版本号
docker pull mysql:版本号
mkdir -p /data/mysql && cd $_ && mkdir {conf,data}
# 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是默认不区分大小写的。
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名称
# 进入docker下mysql容器
docker exec -it webmysql /bin/bash
# 查看指定容器日志
docker logs -f --tail 查看的数量 容器id
# 查看所有容器
docker ps -a
# 删除创建的容器
docker rm 容器id
# 重启容器
docker restart 容器名/容器id