Docker下部署安装Mysql
创始人
2024-03-14 09:04:42
0

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.pidsocket = /var/run/mysqld/mysqld.sockdatadir = /var/lib/mysqlsecure-file-priv= NULL# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Custom config should go here!includedir /etc/mysql/conf.d/max_connections=1000
wait_timeout=120
interactive_timeout=300lower_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

相关内容

热门资讯

汽车油箱结构是什么(汽车油箱结... 本篇文章极速百科给大家谈谈汽车油箱结构是什么,以及汽车油箱结构原理图解对应的知识点,希望对各位有所帮...
美国2年期国债收益率上涨15个... 原标题:美国2年期国债收益率上涨15个基点 美国2年期国债收益率上涨15个基...
嵌入式 ADC使用手册完整版 ... 嵌入式 ADC使用手册完整版 (188977万字)💜&#...
重大消息战皇大厅开挂是真的吗... 您好:战皇大厅这款游戏可以开挂,确实是有挂的,需要了解加客服微信【8435338】很多玩家在这款游戏...
盘点十款牵手跑胡子为什么一直... 您好:牵手跑胡子这款游戏可以开挂,确实是有挂的,需要了解加客服微信【8435338】很多玩家在这款游...
senator香烟多少一盒(s... 今天给各位分享senator香烟多少一盒的知识,其中也会对sevebstars香烟进行解释,如果能碰...
终于懂了新荣耀斗牛真的有挂吗... 您好:新荣耀斗牛这款游戏可以开挂,确实是有挂的,需要了解加客服微信8435338】很多玩家在这款游戏...
盘点十款明星麻将到底有没有挂... 您好:明星麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【5848499】很多玩家在这款游戏...
总结文章“新道游棋牌有透视挂吗... 您好:新道游棋牌这款游戏可以开挂,确实是有挂的,需要了解加客服微信【7682267】很多玩家在这款游...
终于懂了手机麻将到底有没有挂... 您好:手机麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【8435338】很多玩家在这款游戏...