当前位置:网站首页>[玩转Linux] [Docker] MySQL安装和配置
[玩转Linux] [Docker] MySQL安装和配置
2022-07-06 11:33:00 【0xYGC】
简介
不建议在docker里运行MySQL数据库软件,仅当测试或数据重要性不高时使用。生产环境推荐安装到KVM
方法 / 步骤
一:安装MySQL
# 查看docker版本
docker -v
--------------------------------------------
[[email protected] /]# docker -v
Docker version 1.13.1, build 7d71120/1.13.1
--------------------------------------------
1.1 搜索查看可用的MySQL
docker search mysql
1.2 拉取MySQL镜像
# 指定版本
docker pull mysql:5.7
#最新版本
docker pull mysql:latest
1.3 查看本地镜像
docker images
--------------------------------------------------------------------------------------------
[[email protected] /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/mysql 5.7 efa50097efbd 7 days ago 462 MB
--------------------------------------------------------------------------------------------
1.4运行容器
默认端口号 5306
注意docker 参数应该排在MySQL参数之前
docker run \
-p 5306:3306 \
--privileged=true \
--name mysql5306 \
-v /docker/mysql5306/conf:/etc/mysql/conf.d \
-v/docker/mysql5306/logs:/logs \
-v/docker/mysql5306/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=useradmin \
-d mysql:5.7
- 运行成功
二: 修改Docker (MySQL)相关配置
找到容器的配置目录
笔者的配置目录/docker/mysql5306/conf
编辑 my.cnf 文件如果没有就创建一个
- 默认配置文件
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
#数据库默认字符集
character-set-server = utf8mb4
#数据库字符集对应一些排序等规则,注意要和character-set-server对应
collation-server = utf8mb4_general_ci
#设置client连接mysql时的字符集,防止乱码
init_connect=‘SET NAMES utf8mb4‘
#是否对sql语句大小写敏感,1表示不敏感
lower_case_table_names = 1
- 重启容器
docker restart [目标容器id]
三:删除Docker容器
# 查看docker 容器日志,
docker logs ${id}
# 一、查看容器,复制容器id 即container id
docker ps -a
# 二、停止容器
docker stop 你的容器id
# 三、重启容器
docker restart 你的容器id
#三、删除容器
docker rm 容器id
#四、查看镜像,复制镜像id即images id
docker images
#五。删除镜像
docker rmi 镜像id
参考资料 & 致谢
边栏推荐
- 接雨水问题解析
- Black Horse - - Redis Chapter
- short i =1; I=i+1 and short i=1; Difference of i+=1
- Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
- 思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
- How word displays modification traces
- The dplyr package of R language performs data grouping aggregation statistical transformations and calculates the grouping mean of dataframe data
- R语言使用rchisq函数生成符合卡方分布的随机数、使用plot函数可视化符合卡方分布的随机数(Chi Square Distribution)
- How can my Haskell program or library find its version number- How can my Haskell program or library find its version number?
- 三面蚂蚁金服成功拿到offer,Android开发社招面试经验
猜你喜欢
PMP practice once a day | don't get lost in the exam -7.6
Mysql Information Schema 学习(二)--Innodb表
受益匪浅,安卓面试问题
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
利用 clip-path 绘制不规则的图形
A method of removing text blur based on pixel repair
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
How word displays modification traces
三面蚂蚁金服成功拿到offer,Android开发社招面试经验
随机推荐
ModuleNotFoundError: No module named ‘PIL‘解决方法
Simple understanding of MySQL database
Php+redis realizes the function of canceling orders over time
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
凤凰架构2——访问远程服务
Test technology stack arrangement -- self cultivation of test development engineers
Documents to be used in IC design process
Solution of intelligent management platform for suppliers in hardware and electromechanical industry: optimize supply chain management and drive enterprise performance growth
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
How to do smoke test
[pytorch] yolov5 train your own data set
中缀表达式转后缀表达式详细思路及代码实现
CPU负载很低,loadavg很高处理方法
受益匪浅,安卓面试问题
Tongyu Xincai rushes to Shenzhen Stock Exchange: the annual revenue is 947million Zhang Chi and Su Shiguo are the actual controllers
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the grouped dot strip plot, and set the add parameter to add box plots for different levels of dot strip
倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告
【pytorch】yolov5 训练自己的数据集
谷粒商城--分布式高级篇P129~P339(完结)
学习探索-使用伪元素清除浮动元素造成的高度坍塌