I'm working on an application right now which needs to interoperate with an existing application's database. I want to cache some stuff in my NodeJS instance but have no way to subscribe to updates from the existing application. The path of least resistance I figured was to just tail MySQL's binlogs.
Not sure if anyone else would be interested in this, but figured I would put it out there just in case. If there's more interest I can setup a proper github project and put it in npm.
https://gist.github.com/958588
Usage is simple:
var tailer = new MysqlBinlogTailer('/var/lib/mysql/server-binlog.index');
tailer.on('query', function(timestamp, database, query, extra) {
console.log('['+ timestamp+ '] '+ query);
});
A new instance will fast-forward to the end of your binary logs and start emitting events for every query which appears in the binlog. When MySQL rolls over to a new binlog it will automatically move reads over to that one. It's fairly straightforward!
This won't work with mysql<5.0 or mysql>=6.0.