当前位置:网站首页>Mysql-数据丢失,分析binlog日志文件
Mysql-数据丢失,分析binlog日志文件
2022-07-06 21:10:00 【小蜗牛的路】
场景:测试环境中发现少了一部分应该存在的业务数据
a表关联的b表业务数据有28日的数据,但是a表却没有,故去mysql日志查看原因!
属账号的general_log文件存放的目录
mysql> SHOW VARIABLES LIKE 'gen%';
+----------------------------------+----------------------------+
| Variable_name | Value |
+----------------------------------+----------------------------+
| general_log | OFF |
| general_log_file | /var/lib/mysql/server6.log |
| generated_random_password_length | 20 |
+----------------------------------+----------------------------+
3 rows in set (0.01 sec)
然后可以到对应的general_log目录下去看执行日志。
查看binlog
命令行登录数据库:mysql -uroot -p123456
show binary logs;
mysql> show binary logs
-> ;
+---------------+-----------+-----------+
| Log_name | File_size | Encrypted |
+---------------+-----------+-----------+
| binlog.000001 | 385141819 | No |
+---------------+-----------+-----------+
如果需要查询2022-06-28 00:00:00到2022-06-28 23:59:50 数据库为test的操作日志,输入如下命令将数据写入到一个备用的txt即可
mysqlbinlog --no-defaults --database=test --base64-output=decode-rows -v --start-datetime="2022-06-28 00:00:00" --stop-datetime="2022-06-28 23:59:50" binlog.000001 > test.txt;
--base64-output=decode-rows -v
参数:
- base64-output,可以控制输出语句输出base64编码的BINLOG语句;
- decode-rows:选项将把基于行的事件解码成一个SQL语句
通过vi命令,/关键字 查询相关sql
如图:
查看日志,原来该表在29日9:55:41秒被删掉后有重新创建了,所有业务数据丢失!!!
Binlog解析技巧
- 尽可能在从库解析,避免对主库造成影响
- 先粗略定位涉及相关的库表操作的binlog,再单独解析对应的binlog中的数据
- 在解析DDL时无需加
-v
输出详细信息(加快解析速度) - 如果开启了
binlog_rows_query_log_events
参数,需要用-vv
参数才可显示具体的SQL语句
边栏推荐
- ubuntu20安装redisjson记录
- What is Ba? How about Ba? What is the relationship between Ba and Bi?
- Gpt-3 is a peer review online when it has been submitted for its own research
- Kbone与小程序跨端开发的一些思考
- 大白话高并发(二)
- Calculation of time and space complexity (notes of runners)
- Enter the rough outline of the URL question (continuously updated)
- 本机mysql
- 如何检测mysql代码运行是否出现死锁+binlog查看
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
猜你喜欢
[hcie TAC] question 3
【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001
Kotlin Android 环境搭建
Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND
QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
How to customize the shortcut key for latex to stop running
浅谈网络安全之文件上传
随机推荐
The true face of function pointer in single chip microcomputer and the operation of callback function
About Estimation Statistics
Free PHP online decryption tool source code v1.2
List interview common questions
19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
tflite模型转换和量化
Docker部署Mysql8的实现步骤
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
PHP lightweight Movie Video Search Player source code
ggplot 分面的细节调整汇总
Set static IP for raspberry pie
链表面试常见题
Hisilicon 3559 universal platform construction: RTSP real-time playback support
一些常用软件相关
Redis configuration and optimization of NoSQL
Basic concepts of Huffman tree
Search of linear table
21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)
Kotlin Android 环境搭建
VHDL implementation of arbitrary size matrix addition operation