https://cnodejs.org/topic/58378543bde2b59e06141f5a
The first practice is to create a connection and then use, and later found that a period of time will appear after the card is not responding to the situation, only restart the Nodejs service, after searching for a connection pool, after testing, no longer the card is not responding to the situation.
Reference Link: https://www.npmjs.com/package/mysql http://blog.csdn.net/lovingshu/article/details/41721233
node. js MySQL Connection pool module
1, install node's MySQL module npm-install-g node-mysql
2, create a class library, called Mysql_pool.js Bar, then the content is as follows:
VarMysql=Require("MySQL"); VarPool=Mysql.CreatePool({Host: ' localhost ',User: ' User ',Password: ' Password ',Database: ' Database ',Port:Port}); VarQuery=function(Sql,Options,Callback){Pool.Getconnection(function(Err,Conn){ If(Err){Callback(Err,Null,Null); }Else{Conn.Query(Sql,Options,function(Err,results,fields) { Span class= "com" >//release connection Conn. Release//event-driven callback Callback (err , results,fields Span class= "pun" >}); } }); }; module.=query
3, use the following in JS class
var query=require("./lib/mysql_pool"); query("select * from table where id=?", [1], function(err,results,fields){ //do something });
Use of MySQL connection pool in node. js