A mysql binlog listener running on Node.js
A MySQL binlog listener running on Node.js.
ZongJi (踪迹) is pronounced as
zōng jì in Chinese.
This package is a "pure JS" implementation based on
node-mysql. Since v0.2.0, The native part (which was written in C++) has been dropped.
This package has been tested with MySQL server 5.5.40 and 5.6.19. All MySQL server versions >= 5.1.15 are supported.
var zongji = /* ... MySQL Connection Settings ... */ ;// Each change to the replication log results in an eventzongjion'binlog'evtdump;;// Binlog must be started, optionally pass in filterszongjistartincludeEvents: 'tablemap' 'writerows' 'updaterows' 'deleterows';
For a complete implementation see
Requires Node.js v0.10+
$ npm install zongji
Enable MySQL binlog in
my.cnf, restart MySQL server after making the changes.
From MySQL 5.6, binlog checksum is enabled by default. Zongji can work with it, but it doesn't really verify it.
# binlog configserver-id = 1log_bin = /var/log/mysql/mysql-bin.logexpire_logs_days = 10 # optionalmax_binlog_size = 100M # optional# Very important if you want to receive write, update and delete row eventsbinlog_format = row
Create an account with replication privileges, e.g. given privileges to account
zongji (or any account that you use to read binary logs)
REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'zongji'@'localhost'
ZongJi constructor accepts one argument: an object containg MySQL connection details in the same format as used by
Each instance includes the following methods:
|Start receiving replication events|
|None||Disconnect from MySQL server, stop receiving events|
|Change options after |
|Add a listener to the |
|Unique number (1 - 232) to identify this replication slave instance. Must be specified if running more than one instance of ZongJi. Must be used in |
|Array of event names to include|
|Array of event names to exclude|
|Object describing which databases and tables to include (Only for row events). Use database names as the key and pass an array of table names or |
|Object describing which databases and tables to exclude (Same format as |
excludeEventstake precedence over
|Catch any other events|
|New Binlog file (not required to be included to rotate to new files)|
|Before any row event (must be included for any other row events)|
Neither method requires any arguments.
|Log a description of the event to the console|
|Return the name of the event|
node-mysqlare supported by this package.
9007199254740992. Unsigned 64-bit integers must also not exceed
TRUNCATEstatement does not cause corresponding
DeleteRowsevent. Use unqualified
DELETE FROMfor same effect.
I learnt many things from following resources while making ZongJi.