#mysql #binlog #instance #events #networking #runner #mysqlbinlog

bin+lib mysqlbinlog-network

从 MySQL 实例获取 mysqlbinlog

1 个稳定版本

1.0.9 2021 年 7 月 5 日
1.0.6 2021 年 7 月 3 日
1.0.2 2021 年 7 月 2 日

1155数据库接口

MIT/Apache

110KB
2.5K SLoC

mysqlbinlog_network

此创建提供

  • 获取 MySql5.7+/8.0+ Binlog-Event 从 Mysql 实例

功能

  • 支持 macOS、Windows 和 Linux;
  • 支持 Mysql Gtid;
  • 支持 mysql 5.7+/mysql 8.0+ 事件;

安装

将所需版本的 crate 放入您的 dependencies 部分的 Cargo.toml

[dependencies]
mysqlbinlog-network = {git="https://github.com/jiuker/mysqlbinlog_network"}

示例

use mysqlbinlog_network::client::sync::{OffsetConfig, Runner};

fn main() {
    // Use crate[mysql] opt url to connect source
    // ServerID is unique,
    let mut runner = Runner::new("mysql://root:[email protected]:3306", 1111).unwrap();
    runner
        .start_sync(OffsetConfig {
            // pos: Some(("binlog.000002".to_string(), 34834)),
            pos: None,
            gtid: Some("0575a804-6403-11ea-8d3d-e454e8d4a4fe:1-1467870".into()),
        })
        .unwrap();
    loop {
        let e = runner.get_event().unwrap();
        dbg!(e);
    }
}
output:

[src/main.rs:14] e = Event {
        header: EventHeader {
        timestamp: 0,
        event_type: RotateEvent,
        server_id: 2,
        event_size: 43,
        log_pos: 0,
        flags: 32,
    },
    event: Some(
        RotateEvent {
            pos: 4,
            next_log_name: "mysql-bin.000132",
        },
    ),
}
[src/main.rs:14] e = Event {
        header: EventHeader {
        timestamp: 1625022967,
        event_type: FormatDescriptionEvent,
        server_id: 2,
        event_size: 119,
        log_pos: 123,
        flags: 0,
    },
    event: Some(
        FormatDescriptionEvent {
            binlog_version: 4,
            server_version: "5.7.29-log",
            create_timestamp: 0,
            common_header_len: 19,
            checksum_algorithm: CRC32,
        },
    ),
}
[src/main.rs:14] e = Event {
            header: EventHeader {
            timestamp: 1625022967,
            event_type: PreviousGtidsLogEvent,
            server_id: 2,
            event_size: 71,
            log_pos: 194,
            flags: 128,
        },
        event: None,
    }
[src/main.rs:14] e = Event {
        header: EventHeader {
            timestamp: 0,
            event_type: HeartbeatLogEvent,
            server_id: 2,
            event_size: 39,
            log_pos: 4178350,
            flags: 0,
        },
        event: None,
    }
[src/main.rs:14] e = Event {
        header: EventHeader {
        timestamp: 1625047157,
        event_type: GtidLogEvent,
        server_id: 2,
        event_size: 65,
        log_pos: 4178415,
        flags: 0,
    },
    event: Some(
            GtidLogEvent {
                flags: 0,
                uuid: 0575a804-6403-11ea-8d3d-e454e8d4a4fe,
                coordinate: 1467870,
                last_committed: Some(
                    4662,
                ),
                sequence_number: Some(
                    4663,
                ),
            },
        ),
    }
...

API 文档

请参阅[crate 文档]。

事件

  • 未知
  • StartEventV3
  • QueryEvent
  • StopEvent
  • RotateEvent
  • IntvarEvent
  • LoadEvent
  • SlaveEvent
  • CreateFileEvent
  • AppendBlockEvent
  • ExecLoadEvent
  • DeleteFileEvent
  • NewLoadEvent
  • RandEvent
  • UserVarEvent
  • FormatDescriptionEvent
  • XidEvent
  • BeginLoadQueryEvent
  • ExecuteLoadQueryEvent
  • TableMapEvent
  • PreGaWriteRowsEvent
  • PreGaUpdateRowsEvent
  • PreGaDeleteRowsEvent
  • WriteRowsEventV1
  • UpdateRowsEventV1
  • DeleteRowsEventV1
  • IncidentEvent
  • HeartbeatLogEvent
  • IgnorableLogEvent
  • RowsQueryLogEvent
  • WriteRowsEventV2
  • UpdateRowsEventV2
  • DeleteRowsEventV2
  • GtidLogEvent
  • AnonymousGtidLogEvent
  • PreviousGtidsLogEvent
  • OtherUnknown(u8)|

不支持表示事件将不会解析!但事件头部可以告诉你!

许可证

根据以下任一项许可:

感谢

贡献

除非你明确表示,否则任何有意提交以包含在作品中的贡献,根据 Apache-2.0 许可证定义,应按上述方式双许可,没有任何额外的条款或条件。

依赖项

~15–28MB
~451K SLoC