Почему не работает mysql2?
const TelegramBot = require('node-telegram-bot-api');
const mysql = require('mysql2');
const token = "";
const connection = mysql.createConnection({
host: '65.21.149.173',
user: 'admin_samp',
password: 'Asn123As123',
database: 'admin_samp'
});
const bot = new TelegramBot(token, {polling: true});
bot.on('message', (msg) => {
const chatId = msg.from.id;
const text = msg.text;
connection.query("SELECT * FROM `users` WHERE chatId = ?",[chatId], function(err,results) {
if(results == 0){
connection.query("INSERT INTO `users` SET chatId = ?, username = ?, login = ?, lencm = 0", [chatId, msg.from.first_name + ' ' + msg.from.last_name, msg.from.username]);
console.log("New user " + msg.from.first_name + ' ' + msg.from.last_name);
connection.commit();
} else{
console.log("m:", text);
}
});
});
через какое-то время выдаёт ошибку:
Warning: got packets out of order. Expected 5 but received 0
node:events:368
throw er; // Unhandled 'error' event
^
Error: The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.
at Connection.protocolError (C:\Users\Mad\Desktop\bot\node_modules\mysql2\lib\connection.js:394:17)
at Connection.handlePacket (C:\Users\Mad\Desktop\bot\node_modules\mysql2\lib\connection.js:445:14)
at PacketParser.onPacket (C:\Users\Mad\Desktop\bot\node_modules\mysql2\lib\connection.js:85:12)
at PacketParser.executeStart (C:\Users\Mad\Desktop\bot\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket. (C:\Users\Mad\Desktop\bot\node_modules\mysql2\lib\connection.js:92:25)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at Socket.Readable.push (node:internal/streams/readable:228:10)
at TCP.onStreamRead (node:internal/stream_base_commons:199:23)
Emitted 'error' event on Connection instance at:
at Connection.protocolError (C:\Users\Mad\Desktop\bot\node_modules\mysql2\lib\connection.js:397:10)
at Connection.handlePacket (C:\Users\Mad\Desktop\bot\node_modules\mysql2\lib\connection.js:445:14)
[... lines matching original stack trace ...]
at TCP.onStreamRead (node:internal/stream_base_commons:199:23) {
fatal: true,
code: 4031
}