【问题标题】:Mysql-events is not notifying the updated changesMysql-events 没有通知更新的更改
【发布时间】:2017-03-07 02:30:55
【问题描述】:

这是我用来自动通知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] }

【问题讨论】:

    标签: mysql node.js express socket.io


    【解决方案1】:

    您应该考虑修改两件事:

    1. -对于配置试试这个:

      server_id=1 (this is the only important conf you are missing in your file) 
      log-bin = binlog
      binlog_format = row expire-logs-days = 14 (not important to make
      things working) max-binlog-size  = 500M (not important to make
      things working)
      
    2. -从mysqlEventWatcher.add中删除“活动”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 2010-10-19
      • 2016-12-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多