0

I am testing a node.js client which connects to a mysql DB (mariadb). It works fine on its own, but if I launch this client simultaneously on another host, the first instance gets disconnected with the following error. I have read some posts suggesting to change the server-id in my.cnf, but that didn't help. Besides, why would I need to change the id of the server since both clients are pointing to the same server?

{ Error: UNKNOWN_CODE_PLEASE_REPORT: A slave with the same server_uuid/server_id as this slave has connected to the master; the first event 'mysql-b
in.000024' at 334, the last event read from 'mysql-bin.000024' at 256, the last byte read from 'mysql-bin.000024' at 334.
    at Binlog.Sequence._packetToError (/home/myapp/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Binlog.Sequence.ErrorPacket (/home/myapp/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:17)
    at Protocol._parsePacket (/home/myapp/node_modules/mysql/lib/protocol/Protocol.js:278:23)
    at Parser.write (/home/myapp/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/myapp/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/home/myappp/node_modules/mysql/lib/Connection.js:91:28)
    at Socket.<anonymous> (/home/myapp/node_modules/mysql/lib/Connection.js:502:10)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    --------------------
    at Protocol._enqueue (/home/myapp/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Immediate._start (/home/myapp/node_modules/@rodrigogs/zongji/index.js:234:31)
    at processImmediate (timers.js:632:19)
  code: 'UNKNOWN_CODE_PLEASE_REPORT',
  errno: 4052,
  sqlMessage:
   "A slave with the same server_uuid/server_id as this slave has connected to the master; the first event 'mysql-bin.000024' at 334, the last event
 read from 'mysql-bin.000024' at 256, the last byte read from 'mysql-bin.000024' at 334.",
  sqlState: 'HY000' }
{ Error: Connection lost: The server closed the connection.
    at Protocol.end (/home/myapp/node_modules/mysql/lib/protocol/Protocol.js:112:13)
    at Socket.<anonymous> (/home/myapp/node_modules/mysql/lib/Connection.js:97:28)
    at Socket.<anonymous> (/home/myapp/node_modules/mysql/lib/Connection.js:502:10)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at process.internalTickCallback (internal/process/next_tick.js:72:19) fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }
  • You neglected to mention that you are not simply using "a node.js client" but specifically @rodrigogs/zongji, which is actually a binlog listener, and thus must necessarily be registering itself with your server as though it were another server -- and must use a unique value for each connection. Show the code where you are setting up the module and initiating the connection, please. – Michael - sqlbot Mar 6 '19 at 4:22
  • How are you ensuring each connection uses a different server_id? – danblack Mar 6 '19 at 5:09
  • @Michael-sqlbot. That makes a ton of sense. Here is my connection code: – ChrisF Mar 6 '19 at 12:27
  • const DBcon = mysql.createConnection({ host: config.conDB.host, user: config.conDB.user, password: config.conDB.pass, port: config.conDB.port, database: config.conDB.data }); – ChrisF Mar 6 '19 at 12:28
0

@Michael-sqlbot hit it on the nail. Following his suggestion I reviewed the documentation @rodrigogs/zongji and sure enough there is an option to set the serverId. Like so:

const instance = new MySQLEvents(DBcon, {
        startAtEnd: true,
        serverId: 1,
        excludedSchemas: {
                mysql: true,
        }
});
|improve this answer|||||
  • Yes. This value must be different on each concurrent connection, and must also be different from the @@server_id used by any actual MySQL server in the hierarchy. – Michael - sqlbot Mar 6 '19 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.