当前位置:网站首页>[玩转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
参考资料 & 致谢
边栏推荐
- 第五期个人能力认证考核通过名单公布
- [paper notes] transunet: transformers make strongencoders for medical image segmentation
- Dark horse -- redis
- 终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
- 思维导图+源代码+笔记+项目,字节跳动+京东+360+网易面试题整理
- Zero foundation entry polardb-x: build a highly available system and link the big data screen
- 打家劫舍III[后序遍历与回溯+动态规划]
- Mysql Information Schema 学习(二)--Innodb表
- R language uses the order function to sort the dataframe data, and descending sorting based on a single field (variable)
- C # - realize serialization with Marshall class
猜你喜欢
![[paper notes] transunet: transformers make strongencoders for medical image segmentation](/img/21/3d4710024248b62495e2681ebd1bc4.png)
[paper notes] transunet: transformers make strongencoders for medical image segmentation

包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链

Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up

凤凰架构3——事务处理

MRO工业品企业采购系统:如何精细化采购协同管理?想要升级的工业品企业必看!

助力安全人才专业素养提升 | 个人能力认证考核第一阶段圆满结束!

Tongyu Xincai rushes to Shenzhen Stock Exchange: the annual revenue is 947million Zhang Chi and Su Shiguo are the actual controllers

Word如何显示修改痕迹

倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告

Cereals Mall - Distributed Advanced p129~p339 (end)
随机推荐
【翻译】供应链安全项目in-toto移至CNCF孵化器
黑马--Redis篇
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图
打家劫舍III[后序遍历与回溯+动态规划]
ROS自定义消息发布订阅示例
Documents to be used in IC design process
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
English topic assignment (25)
五金机电行业供应商智慧管理平台解决方案:优化供应链管理,带动企业业绩增长
JDBC详解
short i =1; i=i+1与short i=1; i+=1的区别
[translation] a GPU approach to particle physics
Druid 数据库连接池 详解
Elastic search indexes are often deleted [closed] - elastic search indexes gets deleted frequently [closed]
R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
Take a look at how cabloyjs workflow engine implements activiti boundary events
R language uses rchisq function to generate random numbers that conform to Chi square distribution, and uses plot function to visualize random numbers that conform to Chi square distribution
R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the palette parameter, and set the colors of data points and box graphs of dot plots at differ
Word如何显示修改痕迹