zoukankan      html  css  js  c++  java
  • nodejs链接mysql集群,nodejs PoolCluster : Error: Too many connections

    const mysql = require('mysql');
    const config = require('../config/config');
    const poolCluster = mysql.createPoolCluster({
            removeNodeErrorCount: 1, // Remove the node immediately when connection fails.
            defaultSelector: 'RR' //RR,RANDOM,ORDER
        });
        poolCluster.add('node1', config.mysql.node1);
        poolCluster.add('node2', config.mysql.node2);
        poolCluster.add('node3', config.mysql.node3);
        poolCluster.add('node4', config.mysql.node4);
    module.exports = async (sql, options) => {
     
        return new Promise((resolve, reject) => {
            poolCluster.getConnection((err, conn) => {
                if (err) {
                    reject(err)
                } else {
                    conn.query(sql, options, function (error, results, fields) {
                        if (error) {
                            reject(error)
                        } else {
                           conn.release(); 
                     
                            resolve(results);
                        }
                    });
                }
            });
        })
    };
  • 相关阅读:
    python基本数据类型——str
    python基本数据类型——int
    python基本数据类型——set
    python版本与编码的区别
    Servlet基础2
    关于gridview 实现查询功能的方法(转载)
    Python之Socket&异常处理
    Python之面向对象
    Python之模块
    Python之深浅拷贝&函数
  • 原文地址:https://www.cnblogs.com/qiyc/p/11573947.html
Copyright © 2011-2022 走看看