admin管理员组文章数量:1291009
I'm trying to insert a big array of data in MySQL database with node.js. My code works correctly with small array about 300 elements, but when I insert an array with 1M elements I have the following error:
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_mons:211:20)
at Socket.emit (node:events:379:20)
at addChunk (node:internal/streams/readable:313:12) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
My query:
let query = "INSERT INTO transactions (customer_id, tr_date, tr_time, mcc_code, tr_type, amount, term_id) VALUES ?";
connection.query(query, [csvData], (error, response) => {
console.log(error || response);
})
I'm trying to insert a big array of data in MySQL database with node.js. My code works correctly with small array about 300 elements, but when I insert an array with 1M elements I have the following error:
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_mons:211:20)
at Socket.emit (node:events:379:20)
at addChunk (node:internal/streams/readable:313:12) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
My query:
let query = "INSERT INTO transactions (customer_id, tr_date, tr_time, mcc_code, tr_type, amount, term_id) VALUES ?";
connection.query(query, [csvData], (error, response) => {
console.log(error || response);
})
Share
Improve this question
asked Nov 25, 2021 at 19:18
grishabobrgrishabobr
1051 gold badge2 silver badges7 bronze badges
1 Answer
Reset to default 3See here more about the error itself. It's simply a connection error.
Why the connection fails is most likely because that insert is huge and is probably taking a long time to terminate. Also because the data being sent over the network is decent sized, the time the whole operation takes to plete is increased.
The solution to your problem is, IMO, to split the data into multiple smaller inserts (try 500, 1k, 5k, depending on the size of each row).
本文标签:
版权声明:本文标题:javascript - Node JS: Error: read ECONNRESET at TCP.onStreamRead (node:internalstream_base_commons:211:20) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741507374a2382399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论