Skip to content

congpv93/mysql-binlog-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@solashi/go-mysql-binlog-node

A library wrapping the go-mysql package, providing a MySQL client connector and binlog parsing implementation.

This project is forked from go-mysql-js

Installation

npm i --save @solashi/go-mysql-binlog-node
  • Enable MySQL binlog in my.cnf, restart MySQL server after making the changes.

    binlog checksum is enabled by default. @solashi/go-mysql-binlog-node can work with it, but it doesn't really verify it.

    # Must be unique integer from 1-2^32
    server-id        = 1
    # Row format required
    binlog_format    = row
    # Directory must exist. This path works for Linux. Other OS may require
    #   different path.
    log_bin          = /var/log/mysql/mysql-bin.log
    
    binlog_do_db     = employees   # Optional, limit which databases to log
    expire_logs_days = 10          # Optional, purge old logs
    max_binlog_size  = 100M        # Optional, limit log size
    
  • Create an account with replication privileges, e.g. given privileges to account root (or any account that you use to read binary logs)

    GRANT REPLICATION SLAVE, REPLICATION CLIENT, SELECT ON *.* TO 'root'@'localhost'

Example

import MysqlBinlog from '@solashi/go-mysql-binlog-node';

async function main() {
    let syncer = await MysqlBinlog.create({
        hostname: "localhost",
        port: 3306,
        username: "root",
        password: "mypassword",
        tableRegexes: ['Users'],
    });
    syncer.on('event', (event) => {
        console.log('got row event', event);
    });
    syncer.on('error', (err) => {
        console.error('got error', err);
    });

    process.on('SIGINT', function() {
        console.log("Caught interrupt signal");
        syncer.close();
    });
}

main().catch(err => {
    console.error(err);
    process.exit(1);
});

About

Node bindings for go-mysql-org/go-mysql Go library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 55.9%
  • TypeScript 26.5%
  • JavaScript 17.6%