当前位置:网站首页>[玩转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
参考资料 & 致谢
边栏推荐
- php+redis实现超时取消订单功能
- Based on butterfly species recognition
- zabbix 代理服务器 与 zabbix-snmp 监控
- C # use Marshall to manually create unmanaged memory in the heap and use
- Cereals Mall - Distributed Advanced p129~p339 (end)
- ModuleNotFoundError: No module named ‘PIL‘解决方法
- 今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
- Leetcode topic [array] - 119 Yang Hui triangle II
- Interview assault 63: how to remove duplication in MySQL?
- Pytorch common loss function
猜你喜欢
打家劫舍III[后序遍历与回溯+动态规划]
Digital "new" operation and maintenance of energy industry
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
学习探索-使用伪元素清除浮动元素造成的高度坍塌
Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up
Word如何显示修改痕迹
DaGAN论文解读
深入分析,Android面试真题解析火爆全网
Druid database connection pool details
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
随机推荐
Simple understanding of MySQL database
ModuleNotFoundError: No module named ‘PIL‘解决方法
LeetCode-1279. 红绿灯路口
Abstract classes and abstract methods
MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
swagger2报错Illegal DefaultValue null for parameter type integer
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
Interview assault 63: how to remove duplication in MySQL?
第五期个人能力认证考核通过名单公布
zabbix 代理服务器 与 zabbix-snmp 监控
黑马--Redis篇
快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数
五金机电行业供应商智慧管理平台解决方案:优化供应链管理,带动企业业绩增长
R language uses DT function to generate t-distribution density function data and plot function to visualize t-distribution density function data
Modulenotfounderror: no module named 'PIL' solution
Meilu biological IPO was terminated: the annual revenue was 385million, and Chen Lin was the actual controller
Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up
Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!
Mysql Information Schema 学习(一)--通用表
Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan