Overview

= ruby-binlog

== Description

ruby-binlog is Ruby binding for MySQL Binary log API.

see http://www.oscon.com/oscon2011/public/schedule/detail/18785

== Install

gem install ruby-binlog

== Required Privileges

* SUPER
* REPLICATION SLAVE
* EVENT

== Example

  require "binlog"
  
  master_log_file = "mysql-bin.000001"
  master_log_pos = 4
  
  begin
    client = Binlog::Client.new("mysql://repl:repl@example.com")
    sleep 0.3 until client.connect
    client.set_position(master_log_file, master_log_pos)
  
    while event = client.wait_for_next_event
      master_log_pos = event.next_position
  
      case event
      when Binlog::QueryEvent
        puts event.query
      when Binlog::RowEvent
        puts event.event_type
        p event.columns
        p event.rows
      when Binlog::RotateEvent
        master_log_file = event.binlog_file
      else
        puts "(#{event.event_type})"
      end
    end
  rescue Binlog::Error => e
    puts e
    retry if client.closed?
    raise e
  end