当前位置:网站首页>docker安装Mysql和其数据持久化
docker安装Mysql和其数据持久化
2022-08-08 06:20:00 【wuyongde0922】
1.容器化的MySQL的问题
docker容器其实就是在镜像的基础上添加了一个读写层,在容器被删除的时候,容器所保持的数据状态将会丢失,对于MySQL这样的持久数据存储是灾难性的,那么这时候容器的数据持久化就显得很必要了。
2.如何实现持久化
在上一个博客Docker持久化中已经做了详细的介绍,读者可以参考一下。
3.MySQL的数据源文件
Mysql的数据文件一般默认是存储在/var/lib/myql下,其中的文件夹对应每个数据库
#其中的wordpress文件夹就是我名称wordpress对应的数据库
[email protected]:/var/lib/mysql# cd /var/lib/mysql && ls
auto.cnf client-key.pem ibdata1 private_key.pem sys
ca-key.pem ib_buffer_pool ibtmp1 public_key.pem wordpress
ca.pem ib_logfile0 mysql server-cert.pem
client-cert.pem ib_logfile1 performance_schema server-key.pem
进入数据库
[email protected]:/var/lib/mysql# cd wordpress/ && ls
db.opt wp_options.frm wp_term_relationships.ibd wp_usermeta.frm
wp_commentmeta.frm wp_options.ibd wp_term_taxonomy.frm wp_usermeta.ibd
wp_commentmeta.ibd wp_postmeta.frm wp_term_taxonomy.ibd wp_users.frm
wp_comments.frm wp_postmeta.ibd wp_termmeta.frm wp_users.ibd
wp_comments.ibd wp_posts.frm wp_termmeta.ibd
wp_links.frm wp_posts.ibd wp_terms.frm
wp_links.ibd wp_term_relationships.frm wp_terms.ibd
[email protected]:/var/lib/mysql/wordpress#
其中的.frm文件为表结构文件。
其中的.ibd文件为表数据文件。
4.通过volume实现数据库数据持久化
docker run -d \
--name lnmp_mysql -p 3306:3306 \
--net lnmp \
--mount src=mysql-vol,dst=/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456
-e MYSQL_DATABASE=wordpress mysql:5.7
--character-set-server=utf8
使用--mount src=mysql-vol,dst=/var/lib/mysql \绑定数据卷,如果没有数据卷mysql-vol,docker会自动创建,这样容器就会使用宿主机的mysql-vol数据卷,在容器被删除的时候,只需要指定mysql-vol数据卷就可以让容器继续保持原有的数据状态。
边栏推荐
- 4G/5G频谱资源协同关键技术
- Completed - desktop interactive wizard design based on facial expressions (share the results, attach the data set of facial expressions and the yolov5 model trained by yourself and the interactive int
- "Public Administration" exam key points and answers
- 仿记事本;QFile
- MySQL5
- 【matlab】matlab中变量赋值函数deal
- Rust开发——Struct使用示例
- Rust development - Struct usage example
- stack-queue
- What does the "busy" Polkadot latest effort mean for DOT investors?
猜你喜欢

How to batch import files and rename them all to the same file name

分类任务说明

tkinter-TinUI-xml combat (7) PDF paging and merging

开发两年,作为过来人的建议

Web 攻击的日志分析:初学者指南

std::thread创建线程,使用std::ref()传递类对象参数

Neural network to solve what problem, neural network results is not stable

Promise的使用与async/await的使用

Postman显示验证码图片(base64字符串)

神经网络参数量和计算量,神经网络是参数模型吗
随机推荐
时钟的同步与异步问题
云计算和云服务,云计算
仿QQ好友列表,QListWidget!
uvm简介
gcc/g++ use
MySQL6
卷积神经网络 图像识别,卷积神经网络 图像处理
分页组件的使用
基本工具-NETCAT(telnet-banner、传输文本信息)
Runtime——KVC,KVO原理
apifox使用文档之环境变量 / 全局变量 / 临时变量附apifox学习路线图
Unity鼠标光标使用学习
Threads, control, communications
预处理笔记
MySQL database
string hash hash value
Unity mouse cursor usage learning
神经网络一般训练多少次,神经网络训练时间过长
don't know what to name
Synchronization and Asynchrony of Clocks