nodejs 简单的封装一些mysql模块 实现一个方法根据不同传参进行增删改查 首先要 npm install mysql 代码如下 function data(objHost,sql,callback,add=null){ let mysql = require('mysql'); var connection = mysql.createConnection(objHost); connection.connect(); //增删改查 if(add != null){ connection
安装 mysql npm install mysql or cnpm install mysql 创建db.js,实现mysql操作模块 var mysql = require('mysql'); var db = {}; var pool = mysql.createPool({ host: 'localhost', port: 3306, user: 'root', password: 'root', database: 'demo' }); var exec = function (sql
两种方式解决1.你可以配置mysql的连接池 var mysql = require('mysql'); var pool = mysql.createPool({ host: 'localhost', user: 'nodejs', password: 'nodejs', database: 'nodejs', port: 3306 }); var selectSQL = 'select * from t_user limit 10'; pool.getConnection(function