我已经在 MYSQL 数据库中上传了包含 23k 行的 excel 它向我显示错误 "read ECONNRESET"

I have upload the excel with the 23k rows in the MYSQL data base it is showing me the error "read ECONNRESET"

我想使用 Sequelize.js 技术 将 excel 数据上传到 Mysql 数据库中。我使用 bulkCreate 来插入数据。 excel 有 23k+ 行。 当我上传500行数字时,它会顺利上传。但是当我上传大量行时,它会抛出错误

read ECONNRESET

这是我的代码。

const db = require("../model");

const readXlsxFile = require("read-excel-file/node");

const uploadExcel = async (req, res) => {
  try {
    console.log(req.file);
    if (req.file == undefined) {
      return res.status(400).send({ msg: "No, Excel File Uploaded" });
    }

    let path = "./ExcelFiles/" + req.file.filename;

    readXlsxFile(path).then((rows) => {
      // skip header
      rows.shift();

      let ExcelArray = [];

      rows.forEach((row) => {
        let excelarray = {
          id: row[0],
          SoldBy: row[1],
          SoldOn: row[2],
          Quantity: row[3],
          NetProfit: row[4],
          District: row[5],
          OverallGP: row[6],
          Dayofthemonth: row[7],
          Type: row[8],
          TotalNewActivations: row[9],
          TotalUpgrades: row[10],
          DeviceName: row[11],
          Accessories: row[12],
          DistrictManager: row[13],
          StoreName: row[14],
        };

        ExcelArray.push(excelarray);
      });
      // Adding the data in the Database Schema

      if (db.ExcelData.findAll()) {
        db.ExcelData.destroy({ where: {} }).then(function () {});
        db.ExcelData.bulkCreate(ExcelArray)
          .then(() => {
            res.status(200).send({
              message:
                "Uploaded the file successfully: " + req.file.originalname,
            });
          })
          .catch((error) => {
            res.status(500).send({
              message: "Fail to import data into database!",
              error: error.message,
            });
          });
      } else {
        db.ExcelData.bulkCreate(ExcelArray)
          .then(() => {
            res.status(200).send({
              message:
                "Uploaded the file successfully: " + req.file.originalname,
            });
          })
          .catch((error) => {
            res.status(500).send({
              message: "Fail to import data into database!",
              error: error.message,
            });
          });
      }
    });
  } catch (error) {
    console.log(error);
    res.status(500).send({
      message: "Could not upload the file: " + req.file.originalname,
    });
  }
};

//Get the Data from the Mysql

const GetImport = (req, res) => {
  db.ExcelData.findAll()
    .then((data) => {
      res.send(data);
    })
    .catch((err) => {
      res.status(500).send({
        message:
          err.message || "Some error occurred while retrieving tutorials.",
      });
    });
};

module.exports = {
  uploadExcel,
  GetImport,
};

屏幕截图:

问题出在 MySQL 数据库的数据包中。 mySQL 数据库数据包的默认限制是 my.ini 文件中的 16M。

对于大数据,应该设置100M。

文件位置是 C:\ProgramData\MySQL\MySQL Server 8.0/my.ini ,编辑文件并添加

max_allowed_packet = 100M 

对我有用!

谢谢