2016-11-17 63 views
1

我使用的MySQL的Python-複製從MySQL特定的數據庫轉儲數據,這樣我就可以創建參數僅-模式的BinglogStream:的mysql-蟒蛇,複製二進制日誌啓動POS爲特定的模式

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中查找數據庫的開始事件位置?

回答

0

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