每隔一段时间就自动断开连接 怎么搞?
来源:5-10 开发路由(新建和更新博客路由)
纯情掉了一地
2019-10-27
写回答
2回答
-
网上搜一下“mysql 8小时问题”
022019-10-27 -
双越
2019-10-27
参考 https://www.cnblogs.com/maomingchao/p/7447370.html ,看能有帮助吗。
或者修改代码,在连接出错时,就重新建立连接,代码参考
function handleDisconnect() { // Recreate the connection, since // the old one cannot be reused. connection = mysql.createConnection(dbConfig); connection.connect(function(err) { // The server is either down // or restarting if(err) { // We introduce a delay before attempting to reconnect, // to avoid a hot loop, and to allow our node script to // process asynchronous requests in the meantime. console.log('error when connecting to db:', err); setTimeout(handleDisconnect, 2000); } }); connection.on('error', function(err) { console.log('db error', err); if(err.code === 'PROTOCOL_CONNECTION_LOST') { handleDisconnect(); }else{ throw err; } });}
122019-10-27
相似问题
数据库还没断开
回答 1
mac连接mysql报错
回答 3