当前位置:网站首页>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语句
边栏推荐
猜你喜欢

海思3559万能平台搭建:RTSP实时播放的支持

How to customize the shortcut key for latex to stop running

Construction of Hisilicon universal platform: color space conversion YUV2RGB

API data interface of A-share index component data

Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)

Open3d mesh filtering

Adaptive non European advertising retrieval system amcad

Clock in during winter vacation

About Tolerance Intervals

QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
随机推荐
Code quality management
【mysql】mysql中行排序
【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
VHDL implementation of arbitrary size matrix multiplication
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
Flutter3.0, the applet is not only run across mobile applications
The true face of function pointer in single chip microcomputer and the operation of callback function
QT thread and other 01 concepts
Restcloud ETL Community Edition June featured Q & A
太方便了,钉钉上就可完成代码发布审批啦!
二进制、八进制、十六进制
termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
[MySQL] row sorting in MySQL
Can the applet run in its own app and realize live broadcast and connection?
史上最全学习率调整策略lr_scheduler
Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND
浅谈网络安全之文件上传
枚举通用接口&枚举使用规范
[hcie TAC] question 3