这里是用于自动通知的代码,如果mySql数据库中有任何更改到nodeJS,它没有通知?,同时我也编辑了my.cnf文件
#my.cnf文件
binlog_format = row
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = test # Optional, limit which databases to log
节点JS
var MySQLEvents = require('mysql-events');
var dsn = {
host: 'localhost',
user: 'root',
password: 'root',
};
var mysqlEventWatcher = MySQLEvents(dsn);
//console.log(mysqlEventWatcher);
var watcher = mysqlEventWatcher.add(
'test.eventTable',
// test - database name, eventTable - table name
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'
);
我检查了我的连接是否已从节点端建立,如console.log(mysqlEventWatcher);
它响应像
{ 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] }
答案 0 :(得分:0)
您应该考虑修改两件事: