Mysql – Error: “A slave with the same server_uuid/server_id as this slave has connected to the master”

mariadb-10.3MySQLnode.js

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' }

Best Answer

@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,
        }
});