当前位置:网站首页>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语句
边栏推荐
- Clock in during winter vacation
- [MySQL] row sorting in MySQL
- Hisilicon 3559 universal platform construction: RTSP real-time playback support
- When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
- 数据的存储
- HW-小记(二)
- 链表面试常见题
- 22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
- 一些常用软件相关
- Antd Comment 递归循环评论
猜你喜欢
API data interface of A-share index component data
自适应非欧表征广告检索系统AMCAD
Top 50 hit industry in the first half of 2022
When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
Flutter3.0, the applet is not only run across mobile applications
Huawei and Xiaomi "copy each other"
Basic concepts of Huffman tree
Arduino droplet detection
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
[safe office and productivity application] Shanghai daoning provides you with onlyoffice download, trial and tutorial
随机推荐
VHDL implementation of arbitrary size matrix addition operation
QT 打开文件 使用 QFileDialog 获取文件名称、内容等
PHP lightweight Movie Video Search Player source code
VHDL implementation of single cycle CPU design
[hcie TAC] question 3
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
U.S. Air Force Research Laboratory, "exploring the vulnerability and robustness of deep learning systems", the latest 85 page technical report in 2022
Can the applet run in its own app and realize live broadcast and connection?
Mobile measurement and depth link platform - Branch
使用切面实现记录操作日志
codeforces每日5题(均1700)-第七天
Search of linear table
代码质量管理
Top 50 hit industry in the first half of 2022
Calculation of time and space complexity (notes of runners)
Basic concepts of Huffman tree
海思3559万能平台搭建:RTSP实时播放的支持
史上最全学习率调整策略lr_scheduler
Summer 2022 daily question 1 (1)
How to manage the expiration of enterprise distribution certificates- How to manage Enterprise Distribution certificate expiration?