簡體   English   中英

mysql-python-replicator binlog為特定模式啟動pos

[英]mysql-python-replicator binlog start pos for specific schema

我正在使用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中找到數據庫的start事件位置?

猜測第一個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
    )

首先你可以使用resume_stream=False,log_file=None,log_pos=None,blocking=False啟動它,這可能會從頭開始讀取binLogEvents。 在后續迭代中,您應該以某種方式(在db或內存中)記錄最新的log_file和log_pos,您可以從BinLogStreamReader對象中讀取它。 由於blocking參數設置為False因此binlog文件將在事件發生時關閉或由您手動關閉,並且您可以重新創建它,但現在使用您從錄制位置讀取的不同參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM