创建mysql池如何解决 8小时不响应数据库断开情况
程序如下:请问如何解决mysql8小时无请求自动断开的问题,应该在那个部分进行判断
var mysql = require(‘mysql’); var DB_NAME = ‘DB_name’;
var pool = mysql.createPool({ host : ‘localhost’, user : ‘root’, password : ‘123’, port: ‘3306’ });
pool.on(‘connection’, function(connection) {
connection.query(‘SET SESSION auto_increment_increment=1’);
});
pool.getConnection(function(err, connection) {
var useDbSql = "USE " + DB_NAME;
connection.query(useDbSql, function (err) {
if (err) {
console.log("USE Error: " + err.message);
return;
}
console.log('USE succeed');
});
}
8 回复