1、Error: ER_CON_COUNT_ERROR: Too many connections(太多连接池,超出上限)
    如何查看连接池,先到mysql的bin目录下面 用管理员终端打开该目录
    然后起命令登录**mysql -u root -p**
    注意:命令后面要加分号不然不知道你的语句是否结束
    查看 连接池限制的语句 show variables like ‘%max_connections%’
    image.png

    2、使用node-xlsx 第三方插件将excel表格变为数组,然后继续操作

    1. // 引入 node-xlsx 模块
    2. const xlsx = require('node-xlsx');
    3. const db = require('./db.js')
    4. // excel文件类径
    5. const excelFilePath = './data/collegeSummary.xls'
    6. //解析excel, 获取到所有sheets
    7. const sheets = xlsx.parse(excelFilePath);
    8. // 查看页面数
    9. // console.log(sheets.length);
    10. // 打印页面信息..
    11. const sheet = sheets[0];
    12. const allCollegeData = sheet.data.slice(3)
    13. // db.js
    14. const mysql = require("mysql");
    15. const defConfig = {
    16. host: "192.168.1.234",
    17. user: "zywy",
    18. password: "Csqz$%^888",
    19. database: "wangke", // 数据库名
    20. port: "3306",
    21. };
    22. console.log('allCollegeData',allCollegeData)
    23. const connection = mysql.createConnection(defConfig);
    24. connection.connect((err) => {
    25. if (err) {
    26. console.log("数据库连接失败");
    27. throw err;
    28. }
    29. });
    30. let regionIndex = 0;
    31. for(let i = 0; i < allCollegeData.length; i ++) {
    32. let querySql = '';
    33. console.log(`数组长度:${allCollegeData.length},当前索引:${i}, 当前插入项:${allCollegeData[i]}`)
    34. if(allCollegeData[i].length === 1){
    35. //说明是地区项
    36. const currentRegion = allCollegeData[i][0].replace(/\(.*\)/,'');
    37. regionIndex = regionIndex + 1
    38. querySql = `insert into college_region(region) values('${currentRegion}')`;
    39. }else{
    40. const item = allCollegeData[i]
    41. querySql = `insert into college_summary(college_name, college_code, competent_department, college_region, college_levels, region_id) values
    42. ('${item[1]}', '${item[2]}', '${item[3]}', '${item[4]}', '${item[5]}', '${regionIndex}')`;
    43. }
    44. connection.query(querySql);
    45. if(i === allCollegeData.length -1 ) {
    46. console.log('已经处理完毕!')
    47. }
    48. }