mysql 连接池

  
  
  
  
//mysql.js
var mysql = require ( "mysql" );
 
var pool = mysql . createPool ({
host : 'localhost' ,
user : 'root' ,
password : '123456' ,
database : require ( "../config" ). mysql_db ,
connectionLimit : 40
});
 
exports . getConnection = function ( func ) {
pool . getConnection ( func );
};
 
exports . query = function ( sql , params , func ) {
pool . getConnection ( function ( err , conn ) {
var q = conn . query ( sql , params , func );
console . log ( q . sql );
conn . release ();
});
};
 
//use.js
    
    
    
    
//调用
var db = require ( "mysql.js" );
//查询
exports . get = function ( req , res ){
db . query ( "select * from user" ,, function ( err , users ){
return res . render ( 'userList' ,{ users : users );
});
};


你可能感兴趣的:(mysql,pool)