[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>前言
在开发中,需要通过监听mysql的binlog日志文件做到对数据表的监控,由于mysql是部署在docker容器中,还需要解决数据卷的问题
1、通过数据卷的方式开启一个mysql镜像
docker run -p 3307:3306 --name myMysql -v
/usr/docker/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d
mysql:5.7.25
备注:需提前在宿主机目录下创建一个文件用于保存mysql的数据集,我这里创建的目录是 /usr/docker/mysql/data
而/var/lib/mysql是mysql镜像开启后的固定目录,一般是不需要我们手动去干扰的,保持默认的就可以
2、连接mysql并进行测试
使用客户端连接工具连接上mysql,尝试着观察一下mysql_binlog的开启情况
可以看到此时并没有开启日志功能,同时我们也可以去到宿主机的挂载目录下观察一下,
3、开启bin_log
依次执行下面的命令
docker exec myMysql bash -c "echo 'log-bin=/var/lib/mysql/mysql-bin' >>
/etc/mysql/mysql.conf.d/mysqld.cnf" docker exec myMysql bash -c "echo
'server-id=123454' >> /etc/mysql/mysql.conf.d/mysqld.cnf"
4、重启mysql镜像
docker restart myMysql
5、创建一个数据库并在里面创建一个表加一条数据
这时我们再观察一下bin_log的变化,说明这时候bin_log的日志已经生成了
也可以进入到宿主机目录下进行观察,这时在宿主机下已经产生了日志文件
<>结语
本篇的初衷是为了快速搭建mysql并能想办法检测到bin_log的日志达到后续使用bin_log检测表数据变化的目的,因此使用docker安装贺启动mysql是比较方便的,但由于是初次尝试,在网上参考相关的资料时发现基大多数博客的内容基本上没有经过验证,或者说很难实施出效果,最终总结出上面可执行的流程,提供后续的参考和使用!友情提示,网上的资料请慎重参考!最后感谢观看!