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
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
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] }