gpt4 book ai didi

python - mysql-python-replicator binlog 特定模式的启动位置

转载 作者:行者123 更新时间:2023-11-30 21:22:11 24 4
gpt4 key购买 nike

我正在使用 mysql-python-replicator 从 mysql 转储特定数据库的数据,因此我可以创建一个带有参数 only-schema 的 BinglogStream:

stream = BinLogStreamReader(connection_settings=mysql_settings,
server_id=1,only_schemas='tpch',
log_file='mysql-bin.000001',log_pos=1
)

我有参数log_file='mysql-bin.000001'log_pos=1,因为我不知道事件位置从哪里开始,所以任何想法在 mysql-binlog 中找到数据库的开始事件位置?

最佳答案

猜测第一个 binlog 位置是行不通的。服务器上可能不存在此文件和位置,因为 Mysql 会根据其配置自动轮换这些日志。

图书馆内部知道如何从头开始。只需省略恢复所需的 3 个参数(或将它们设置为 False/None):

if binlog_filename is None or binlog_position is None:
# Connecting to MySQL binlog (from beginning)...
binlog_stream = BinLogStreamReader(
connection_settings=mysql_settings,
server_id=1,
blocking=True
)
else:
# Continuing from binlog_filename and binlog_position
binlog_stream = BinLogStreamReader(
connection_settings=mysql_settings,
server_id=1,
resume_stream=True,
blocking=True,
log_file=binlog_filename,
log_pos=binlog_position
)

关于python - mysql-python-replicator binlog 特定模式的启动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40657183/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com