当前位置:网站首页>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语句
边栏推荐
- 如何自定义Latex停止运行的快捷键
- My brave way to line -- elaborate on what happens when the browser enters the URL
- SQL injection -day15
- .net中 接口可以有默认实现了
- 2022年上半年HIT行业TOP50
- 一些常用软件相关
- [leetcode] 700 and 701 (search and insert of binary search tree)
- API data interface of A-share index component data
- PIP download only, not install
- Adaptive non European advertising retrieval system amcad
猜你喜欢
随机推荐
Clock in during winter vacation
[leetcode] 450 and 98 (deletion and verification of binary search tree)
数据的存储
如何自定义Latex停止运行的快捷键
Set static IP for raspberry pie
Open3d mesh filtering
Termux set up the computer to connect to the mobile phone. (knock the command quickly), mobile phone termux port 8022
VHDL implementation of arbitrary size matrix multiplication
How to customize the shortcut key for latex to stop running
Top 50 hit industry in the first half of 2022
HW notes (II)
概率论公式
Hisilicon 3559 universal platform construction: RTSP real-time playback support
Kotlin Android environment construction
【安全攻防】序列化与反序列,你了解多少?
Calculation of time and space complexity (notes of runners)
Antd Comment 递归循环评论
Summer 2022 daily question 1 (1)
Restcloud ETL Community Edition June featured Q & A
VHDL implementation of single cycle CPU design








