Nodejs MySQL Pool usage example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.