Registry / database / mysql-events

mysql-events

JSON →
library0.0.11jsnpmunverified

A Node.js package that watches a MySQL database using binary log (binlog) parsing via ZongJi, allowing callbacks on table/column changes. v0.0.11, last updated 2016. Low maintenance, no recent releases. Alternative to polling-based watchers, but requires MySQL binlog enabled and appropriate privileges. Based on ZongJi (now unmaintained).

npm install mysql-events
INSTALL
IMPORT
SIG · MYSQL-EVENTS
M
mysql-events
databasejavascriptv0.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const MySQLEvents = require('mysql-events');
import MySQLEvents from 'mysql-events';
Package provides only a CommonJS default export (ESM import incorrectly gives undefined).
MySQLEvents
const MySQLEvents = require('mysql-events');
const { MySQLEvents } = require('mysql-events');
The default export is a function, not a named export.
Instance (returned by MySQLEvents(dsn))
const watcher = MySQLEvents(dsn); watcher.add(...); watcher.stop();
new MySQLEvents(dsn);
MySQLEvents is a factory function, not a constructor. Do not use 'new'.

Connects to MySQL, adds a watcher on a specific column for a value, and logs insert/update/delete events.

const MySQLEvents = require('mysql-events'); const dsn = { host: process.env.MYSQL_HOST ?? 'localhost', user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '' }; const mysqlEventWatcher = MySQLEvents(dsn); const watcher = mysqlEventWatcher.add( 'myDB.myTable.myColumn', function (oldRow, newRow, event) { if (oldRow === null) { console.log('Insert:', newRow); } else if (newRow === null) { console.log('Delete:', oldRow); } else { console.log('Update:', oldRow, 'to', newRow); } }, 'someValue' ); // To stop the watcher: // watcher.remove(); // or mysqlEventWatcher.stop();
Debug
Known issues
gotchaMySQLEvents is a factory function, not a constructor. Calling with 'new' will not work correctly.
fix
Use MySQLEvents(dsn) without 'new'.
affects: *
gotchaThe default startAtEnd option is true; events that occurred before connection are not captured. Set { startAtEnd: false } if you need to read from the beginning of the binlog.
fix
Pass { startAtEnd: false } as second argument to MySQLEvents(dsn, { startAtEnd: false }).
affects: *
gotchaThe expression parameter (third argument to add()) is used inconsistently: with 4-part pattern it must match the value exactly; with 3-part pattern it is ignored.
fix
Use a 4-part pattern (db.table.column.value) to filter by a specific value, or use a regex as the third argument with a 4-part pattern.
affects: *
gotchaMySQL user must have REPLICATION SLAVE, REPLICATION CLIENT, and SELECT privileges to read binlog and table data.
fix
Grant appropriate privileges: GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO 'user'@'host';
affects: *
deprecatedThe underlying ZongJi package is no longer actively maintained; consider alternatives like mysql-events or direct binlog parsing.
fix
Evaluate alternative libraries such as 'mysql2' with binlog parsing or 'rplparse'.
affects: *
Errors
Common errors & fixes
TypeError: MySQLEvents is not a constructor
Using new MySQLEvents(dsn) instead of calling as a function.
fix
Change to MySQLEvents(dsn) without 'new'.
Error: ER_SPECIFIC_ACCESS_DENIED: Access denied; you need (at least one of) the REPLICATION SLAVE privilege(s) for this operation
MySQL user does not have required binlog privileges.
fix
Grant REPLICATION SLAVE and REPLICATION CLIENT privileges to the user.
Error: ER_BINLOG_ROW_MODE: Cannot execute statement: binlog must be in ROW format for this library to work.
MySQL binlog format is not ROW.
fix
Set binlog_format=ROW in MySQL configuration (requires restart).
Upgrade
Version history
0.0.11latest on npm
Audit
Dependencies
zongjirequiredCore dependency for MySQL binlog parsing; all functionality depends on it.
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-events — npm install mysql-events · libregistry