【 TiDB 使用环境】生产环境
【 TiDB 版本】6.5.0
【复现路径】做过哪些操作出现的问题
【遇到的问题:问题现象及影响】
【资源配置】进入到 TiDB Dashboard -集群信息 (Cluster Info) -主机(Hosts) 截图此页面
【复制黏贴 ERROR 报错的日志】
【其他附件:截图/日志/监控】
tidb老版本有binlog可以解析,不过最新版本的tidb把binlog废弃了
可以吧binlog输出到文件
(https://docs.pingcap.com/zh/tidb/v8.3/tidb-binlog-configuration-file#db-type)
然后用解析工具 Reparo解析binlog
https://docs.pingcap.com/zh/tidb/v8.3/tidb-binlog-reparo
2 个赞
用reparo解析的文件不是sql,跟mysql的binlog格式也是有区别的。不知道能否满足你的需求。
例如:
MySQL [test]> create table t1(id int primary key,name varchar(20));
Query OK, 0 rows affected (0.13 sec)
MySQL [test]> insert into test.t1 values(1,'a'),(2,'b'),(3,'c');
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
MySQL [test]> update test.t1 set name='d' where id =3;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MySQL [test]> delete from test.t1 where id =2;
Query OK, 1 row affected (0.02 sec)
解析出来为:
DDL query: use `test`; CREATE TABLE `t1` (`id` INT PRIMARY KEY,`name` VARCHAR(20));;
[2025/02/24 02:54:14.814 -05:00] [INFO] [reparo.go:83] ["sync binlog success"] [ts=456231031332929570] [datetime=2025/02/24 02:47:47.719 -05:00]
schema: test; table: t1; type: Insert
id(int): 1
name(varchar): a
schema: test; table: t1; type: Insert
id(int): 2
name(varchar): b
schema: test; table: t1; type: Insert
id(int): 3
name(varchar): c
[2025/02/24 02:54:14.814 -05:00] [INFO] [reparo.go:83] ["sync binlog success"] [ts=456231031962075144] [datetime=2025/02/24 02:47:50.119 -05:00]
schema: test; table: t1; type: Update
id(int): 3 => 3
name(varchar): c => d
[2025/02/24 02:54:14.814 -05:00] [INFO] [reparo.go:83] ["sync binlog success"] [ts=456231033167675406] [datetime=2025/02/24 02:47:54.718 -05:00]
schema: test; table: t1; type: Delete
id(int): 2
name(varchar): b
[2025/02/24 02:54:14.814 -05:00] [INFO] [reparo.go:83] ["sync binlog success"] [ts=456231034032750598] [datetime=2025/02/24 02:47:58.018 -05:00]
[2025/02/24 02:54:14.814 -05:00] [INFO] [read.go:123] ["read file end"] [file=/tidb-deploy/drainer-8249/binlog-0000000000000000-20250224015736]
可以开启general log,记录所有执行的sql
要么开general log自己去处理;要么直接上企业版,审计是个付费功能。
https://docs.pingcap.com/zh/tidb/stable/ticdc-sink-to-cloud-storage
cdc 放输出 csv/json 文件到存储里面,自己解析文件内容即可。
1 个赞
跟mysql一样,可以开启general log,记录所有执行的sql语句