node + mysql,當(dāng)8小時沒有查詢數(shù)據(jù)庫時,則會斷開連接
mysql > show variables like 'wait_timeout';
解決辦法,設(shè)置一個定時器,每隔5小時就自動查詢一次數(shù)據(jù)
function keepConnection(){
connection.query('select count(1) from user', function(error, result) {
if (error) return console.log(error);
})
}
setInterval(keepConnection, 1000*60*60*5);