The reason is that if the connection is lost due to network reasons after the node connects to MySQL or the user closes the connection manually, the original connection will be suspended and the connection needs to be reconnected.Code, Closed at the end of each access, and re-connected before each access, the Code does not listen to the fatal error of the connection, copy should be careful
VaR MySQL = require ('mysql'); var connection = MySQL. createconnection ({Host: 'localhost', user: 'root', password: '000000', database: 'test'}), slice = []. slice; var commonmethod = function (callback) {connection = MySQL. createconnection (connection. config); connection. connect (); callback. call (connection, callback); connection. end () ;}; var onerror = function () {console. log (ERR) ;}; var query = function () {var ARGs = arguments; commonmethod (function () {connection. query. apply (connection, argS ). on ('error', onerror );});};