不说废话,代码:
const mysql = require('mysql');//建立连接池let pool = mysql.createPool({host: 'localhost',user: 'root',password: '123456',port: '3306',database: 'node1',connectionLimit: 10 //连接池大小});
使用:
this.addContent = function (data) {//使用pool.getConnection((err, connection) => {if (err) {console.log("连接失败");} else {connection.query(addSql, addSqlParams, function (err, result) {if (err) {console.log('[ERROR] - ', err.message);return;}console.log('result:\n', result);});//释放connection.release();}});};