最近线上的进程总是自己挂掉,查看nohup.out文件,发现是mysql链接久了,超时自动关闭链接了,网上搜索了一些解决办法,可依然没有解决。求大神帮忙,谢啦!
Error: Connection lost: The server closed the connection.
下面是我的代码:
var mq = require("mysql"); global.mc = mq.createConnection({ host:"192.168.1.113", user: "root", password: "root" }); var connectionState = false; function connectMySql(){ mc.connect(function(err){ if(err){ console.log('SQL connect err:'+err); connectionState = false; } else{ console.log('SQL connect successful!'); connectionState = true; } }); mc.on('close', function (err) { logger.error('mysqldb conn close'); connectionState = false; }); mc.on('error', function (err) { logger.error('mysqldb error: ' + err); connectionState = false; }); } connectMySql(); var dbConnChecker = setInterval(function(){ if(!connectionState){ connectMySql(); } },500);
5 回复