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);
}
});
}
});
})
};