[英]error while inserting LARGE volume data in mysql by using node.js (error code: 'ECONNRESET')
使用node.js在mysql中插入大量數據時遇到錯誤這里是數據
instData = [ [ '73caf3d0-f6a4-11e8-8160-eb5f91ce3830',
'20181017'],
[ '73caf3d1-f6a4-11e8-8160-eb5f91ce3830',
'20181019'],
... 49316 more items ]
這是連接代碼的一部分:
let pool = mysql.createPool(db);
module.exports = {
connPool (sql, val, cb) { //function name
pool.getConnection((err, conn) => {
if(err){
console.log('Connection Error:' + err);
}else{
console.log('allConnections:' + pool._allConnections.length);
let q = conn.query(sql, val, (err, rows,fields) => {
if (err) {
console.log('Query:' + sql + ' error:' + err);
}
cb(err, rows, fields);
conn.release();
});
} // end if
}); // end pool.getConnection
},
......
當我運行插入代碼時,出現錯誤。
sql_inst ='insert into demo (id,upload_time) values ?';
func.connPool(sql_inst, [instData], (err,rows,fields) => {
if(err==null){
res.json({code: 200, msg: 'success', data: req.body });
} else {
res.json({code: 400, msg: 'failed:'+err});
}
});
錯誤信息:
{ Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
--------------------
at Protocol._enqueue (D:\Projects\test\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at PoolConnection.query (D:\Projects\test\node_modules\mysql\lib\Connection.js:200:25)
at pool.getConnection (D:\Projects\test\sql\func.js:29:26)
at Ping.onOperationComplete (D:\Projects\test\node_modules\mysql\lib\Pool.js:110:5)
at Ping.<anonymous> (D:\Projects\test\node_modules\mysql\lib\Connection.js:502:10)
at Ping._callback (D:\Projects\test\node_modules\mysql\lib\Connection.js:468:16)
at Ping.Sequence.end (D:\Projects\test\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
at Ping.Sequence.OkPacket (D:\Projects\test\node_modules\mysql\lib\protocol\sequences\Sequence.js:92:8)
at Protocol._parsePacket (D:\Projects\vutest\node_modules\mysql\lib\protocol\Protocol.js:278:23)
at Parser.write (D:\Projects\test\node_modules\mysql\lib\protocol\Parser.js:76:12)
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read',
fatal: true }
似乎連接已關閉,但問題是我使用連接池,它不應該每次都連接。
當我減小數據大小時,fg 數據包含 100 條記錄,代碼運行成功。
運行環境:節點:v10.11.0 mysql:v5.7
我解決這個問題有多冷? 偉大的thx!
我已經解決了這個問題。 它是由默認定義 max_allowed_packet 引起的。 在 my.ini (C:\\ProgramData\\MySQL\\MySQL Server 5.7) 中找到 max_allowed_packet。 更新為“max_allowed_packet=64M”。 重啟mysql。 完畢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.