diff --git a/README.md b/README.md index db44b856..f2b041db 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ from pymysqlreplication import BinLogStreamReader mysql_settings = {'host': '127.0.0.1', 'port': 3306, 'user': 'root', 'passwd': ''} -stream = BinLogStreamReader(connection_settings = mysql_settings) +stream = BinLogStreamReader(connection_settings = mysql_settings, server_id=2) for binlogevent in stream: binlogevent.dump() @@ -322,5 +322,3 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - - diff --git a/pymysqlreplication/binlogstream.py b/pymysqlreplication/binlogstream.py index 56f42a88..9d7cc1e2 100644 --- a/pymysqlreplication/binlogstream.py +++ b/pymysqlreplication/binlogstream.py @@ -13,7 +13,7 @@ from .event import ( QueryEvent, RotateEvent, FormatDescriptionEvent, XidEvent, GtidEvent, StopEvent, - BeginLoadQueryEvent, ExecuteLoadQueryEvent, + BeginLoadQueryEvent, ExecuteLoadQueryEvent, IntvarEvent, NotImplementedEvent) from .row_event import ( UpdateRowsEvent, WriteRowsEvent, DeleteRowsEvent, TableMapEvent) @@ -260,7 +260,11 @@ def __connect_to_stream(self): if self.log_file is None or self.log_pos is None: cur = self._stream_connection.cursor() cur.execute("SHOW MASTER STATUS") - self.log_file, self.log_pos = cur.fetchone()[:2] + output = cur.fetchone() + if not output: + raise Exception('Server is not master') + cur.close() + self.log_file, self.log_pos = output[:2] cur.close() prelude = struct.pack('