A period of time before writing a version of the release tool, using the EXPRESS+MYSQL implementation, when the site is running a long period of blank time, the node process will automatically down, prompted the MySQL connection error, Google found that the characteristics of MySQL itself caused, and subsequently changed to MySQL Pool even solves the problem!
MySQL Module for Felixge/node-mysql
The source code is as follows:
/** * created by kevalin on 2015/4/22. */var express = Require (' Express '); var router = express. Router (); Var mysql = require (' MySQL '); Var conf = require ('.. /config/dbconnection ');//define Pool Var pool = mysql.createpool ( { host : conf.dbmysql.host, user : conf.dbMysql.user, password : conf.dbMysql.password, database : conf.dbMysql.database, port : conf.dbmysql.port }); Router.get ('/', Function (rEq, res) { var selectSites = "Select *, date_format ( do_time, '%y-%m-%d %h:%i:%s ') as time from siteinfo order by id "; pool.getconnection (function (err, connection) { if (ERR) throw err; Connection.query (Selectsites, function (err, rows) { if (ERR) throw err; res.render (' sites ', {title : ' site distribution ', results : rows}) }); //recovery Pool connection.release (); }); Module.exports = routEr
Nodejs MySQL Pool usage example