spencerlambert / mysql-events

A node meteor package that watches a MySQL database and runs callbacks on matched events.
Other
89 stars 75 forks source link

the connection is not get establishing ? #15

Closed wayfork closed 8 years ago

wayfork commented 8 years ago

Here the code which I am using for auto notifying if there is any change in mySql database to nodeJS, it dosn't notifying?, at the same time I have edited my.cnf file and GRANT privilages to the user too

my.cnf file

binlog_format = row
log_bin         = /var/log/mysql/mysql-bin.log
binlog_do_db     = test   # Optional, limit which databases to log

nodeJS

var MySQLEvents = require('mysql-events'); var dsn = { host: 'localhost', user: 'root', password: 'root', }; var mysqlEventWatcher = MySQLEvents(dsn); console.log(mysqlEventWatcher); // connection is disconnect var watcher = mysqlEventWatcher.add( 'test.eventTable', function (oldRow, newRow) { //row inserted console.log(oldRow); console.log('_'); console.log(newRow); console.log('_'); if (oldRow === null) { //insert code goes here } //row deleted if (newRow === null) { //delete code goes here } //row updated if (oldRow !== null && newRow !== null) { //update code goes here } }, 'Active' );

while console the connection :

var mysqlEventWatcher = MySQLEvents(dsn); console.log(mysqlEventWatcher); // connection is disconnect

{ started: false, zongji: ZongJi { options: {}, domain: null, _events: { error: [Function] }, _eventsCount: 1, _maxListeners: undefined, ctrlConnection: Connection { domain: null, _events: {}, _eventsCount: 0, _maxListeners: undefined, config: [Object], _socket: [Object], _protocol: [Object], _connectCalled: true, state: 'disconnected', threadId: null }, ctrlCallbacks: [], connection: Connection { domain: null, _events: {}, _eventsCount: 0, _maxListeners: undefined, config: [Object], _socket: undefined, _protocol: [Object], _connectCalled: false, state: 'disconnected', threadId: null }, tableMap: {}, ready: false, useChecksum: false }, databases: [], tables: {}, columns: {}, events: [ 'tablemap', 'writerows', 'updaterows', 'deleterows' ], triggers: [], connect: [Function], add: [Function], remove: [Function], stop: [Function], reload: [Function], includeSchema: [Function] }

spencerlambert commented 8 years ago

Have you granted replication privileges to your mysql user?

https://dev.mysql.com/doc/refman/5.7/en/replication-howto-repuser.html

wayfork commented 8 years ago

its working after the privileges set properly. Thanks @spencerlambert