mysql
mysql copied to clipboard
Error: Packets out of order. Got: 32 Expected: 0
I have a problem Need advice I don't know how to fix it.
Code :
var mysql = require('mysql');
var con = mysql.createConnection({
host: "xx.xxx.xx.xx",
port: xxxx,
user: "xxxxxx",
password: "xxxxxx",
database:"xxxxxxxx",
debug:true
});
con.connect(function(err) {
if (err){
console.log("Not Connected 1!---->> "+err.stack);
}
else{
console.log("Connected!");
con.query("SELECT * FROM xxxx", function (err, result, fields) {
if (err){
console.log("Not Connected 2!---->> "+err);
}
console.log(result);
connection.end();
});
}
});
Result :
Usually that error during connect means likely whatever is at the host and port specified is not a mysql server.
I just had the following error: Error: Packets out of order. Got: 1 Expected: 0.
If anyone finds this issue while looking for a solution: For me this was because I had skip-name-resolve in my mysql server config while my mysql users had localhost as host and the nodejs app was connecting via the tcp socket.
The solution is to either remove skip-name-resolve from the config, change the host of the mysql users to 127.0.0.1 or connect via the unix domain socket instead. I chose the last option and am now connecting via a unix domain socket using the socketPath connection option.
See https://stackoverflow.com/a/49137984
