使用for-in循环时在binLogStreamReader中阻止

时间:2019-05-24 05:40:42

标签: python-2.7 mysqlbinlog

当我在线使用mysql服务器时运行此代码

 for binlogevent in self.stream:
                binlogevent.dump()

它将阻塞for循环,当我执行ctrl + c时将显示此错误,您可以看到它在哪里阻塞

  File "test_binlog.py", line 126, in main
    for binlogevent in self.stream:
  File "/usr/lib/python2.7/site-packages/pymysqlreplication/binlogstream.py", line 413, in fetchone
    pkt = self._stream_connection._read_packet()
  File "/usr/lib64/python2.7/site-packages/pymysql/connections.py", line 657, in _read_packet
    packet_header = self._read_bytes(4)
  File "/usr/lib64/python2.7/site-packages/pymysql/connections.py", line 691, in _read_bytes
    data = self._rfile.read(num_bytes)
  File "/usr/lib64/python2.7/site-packages/pymysql/_socketio.py", line 59, in readinto
    return self._sock.recv_into(b)

这是BinLogStreamReader设置

self.stream=BinLogStreamReader(connection_settings=mysql_settings, server_id=187, blocking=True,
                                         only_schemas=[MSYQL_DB_MAGIC], only_tables=self.play_tables,
                                         only_events=[DeleteRowsEvent, WriteRowsEvent, UpdateRowsEvent])

我知道在mysql设置中可能是错误的,因为我在测试环境中与其他mysql一起运行了此代码,没关系。

但是在在线mysql中,请确保打开binlog。并且表和模式肯定存在。并运行一些代码show mysql binlog setting,它将显示这样的消息

('exec ', 'show binary logs;')
================data============================
{u'Log_name': u'mysql-bin.000350', u'File_size': 20707324}
================data============================
{u'Log_name': u'mysql-bin.000351', u'File_size': 9753176}
================data============================
{u'Log_name': u'mysql-bin.000352', u'File_size': 5874922}
================data============================
{u'Log_name': u'mysql-bin.000353', u'File_size': 10822235}

('exec ', "show variables like 'binlog_format'")
================data============================
{u'Value': u'ROW', u'Variable_name': u'binlog_format'}

('exec ', "show variables like '%log_bin%'")
================data============================
{u'Value': u'ON', u'Variable_name': u'log_bin'}
================data============================
{u'Value': u'', u'Variable_name': u'log_bin_basename'}
================data============================
{u'Value': u'', u'Variable_name': u'log_bin_index'}
================data============================
{u'Value': u'ON', u'Variable_name': u'log_bin_trust_function_creators'}
================data============================
{u'Value': u'ON', u'Variable_name': u'log_bin_use_v1_row_events'}
================data============================
{u'Value': u'OFF', u'Variable_name': u'rocksdb_enable_log_binlog_info'}
================data============================
{u'Value': u'ON', u'Variable_name': u'sql_log_bin'}

我不知道这是怎么发生的,所以我写了这个来寻求帮助。

谢谢。

0 个答案:

没有答案