forked from flydata/ruby-binlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
102 lines (80 loc) · 2.27 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
= ruby-binlog
== Description
ruby-binlog is Ruby binding for MySQL Binary log API.
* http://www.oscon.com/oscon2011/public/schedule/detail/18785
* https://launchpad.net/mysql-replication-listener
* https://bitbucket.org/winebarrel/mysql-replication-listener
== Install
gem install ruby-binlog
== Required Privileges
* SUPER
* REPLICATION SLAVE
* EVENT
== Example
#!/usr/bin/env ruby
require "rubygems"
require "binlog"
require "pstore"
$db = PStore.new("/tmp/foo")
#master_log_file = "mysql-bin.000001"
#master_log_pos = 4
master_log_file = nil
master_log_pos = nil
$db.transaction do
master_log_file = $db["master_log_file"]
master_log_pos = $db["master_log_pos"]
end
def save_position(master_log_file, master_log_pos)
$db.transaction do
$db["master_log_file"] = master_log_file
$db["master_log_pos"] = master_log_pos
end
end
begin
# XXX: Do not reuse a client instance, after connection goes out.
client = Binlog::Client.new("mysql://repl:[email protected]")
sleep 0.3 until client.connect
if master_log_file and master_log_pos
client.set_position(master_log_file, master_log_pos)
end
while event = client.wait_for_next_event
puts "(#{event.event_type})"
master_log_pos = event.next_position
case event
when Binlog::QueryEvent
puts event.db_name
puts event.query
save_position(master_log_file, master_log_pos)
when Binlog::RowEvent
puts event.event_type
puts event.db_name
puts event.table_name
p event.columns
p event.rows
save_position(master_log_file, master_log_pos)
when Binlog::RotateEvent
master_log_file = event.binlog_file
master_log_pos = event.binlog_pos
save_position(master_log_file, master_log_pos)
end
end
rescue Binlog::Error => e
puts e
retry if client.closed?
raise e
end
== Notice
The following type are not supported in row mode.
* DECIMAL
* INT24
* DATE
* TIME
* YEAR
* BIT
* ENUM
* SET
* GEOMETRY
see the following urls:
* http://bazaar.launchpad.net/~mysql/mysql-replication-listener/trunk/view/head:/src/value.cpp#L310
* https://bitbucket.org/winebarrel/ruby-binlog/downloads
* There is a patch of a library.