0
我使用node-mysql2並在MySQL中存儲字符串編碼的二進制數據。該列的類型爲binary(16)
。存儲在MySQL的數據被損壞,例如:存儲在MySQL中的二進制數據被損壞節點
NodeJS output: 47 23 43 14 ed 86 14 dc 12 f3 b8 6c dc 31 fb fa
MySQL HEX() : 47 23 43 14 c3 ad c2 86 14 c3 9c 12 c3 b3 c2 b8
代碼:
var binaryString = randomBinaryString();
db.sqlQuery("INSERT INTO test(binaryString) VALUES(" + db.escape(binaryString) + ")");
console.log(new Buffer(binaryString, 'binary').toString('hex'));
function randomBinaryString(){
var str = "";
for(var i = 0; i < 16; i++){
str += String.fromCharCode(Math.floor(Math.random()*256));
}
return str;
}
應如何實際二進制數據編碼(每個字符是一個字節)的字符串使用節點被存儲在MySQL -mysql2?