Node.js MySQL连接问题
Node.js MySQL Connection Issue
有什么问题
- 我使用节点mysql连接到mysql
- 我很难处理这里提到的
server disconnects
/wait_timeouts
:https://github.com/felixge/node-mysql#server-断开 - 每次在处理
PROTOCOL_CONNECTION_LOST
错误时尝试重新创建连接后,我都会收到错误消息:This socket has been ended by the other party
我想做什么
// Connect Function
db.connect = function(callback){
// Destory the Connection if there is already one
if(db.connection) {
console.log('[mysql]','connection destroy');
db.connection.destroy();
db.connection = null;
}
// Create the Connection
db.connection = MySQL.createConnection(options);
// Connect using the Connection
db.connection.connect(function(error) {
if(error){
console.log('[mysql]', 'connect failed', error);
} else {
console.log('[mysql]', 'connection success');
db.connection.database = options.database;
callback(db.connection, error);
}
});
// Listen on Connection Errors
db.connection.on('error', function(error) {
// Connection to the MySQL server is usually
// lost due to either server restart, or a
// connnection idle timeout (the wait_timeout server variable configures this)
if(error.code === 'PROTOCOL_CONNECTION_LOST') {
console.log('[mysql]', 'PROTOCOL_CONNECTION_LOST')
db.connect(callback);
} else {
console.log('[mysql] Connection Error: ', error);
}
});
// Return Connection Instance
return db.connection;
}
其他详细信息
CCD_ 5和CCD_ 6必须在CCD_。
[mysqld]
wait_timeout = 10
interactive_timeout = 10
在接收到FIN数据包后,库意外地试图重写TCP套接字,这意味着TCP连接被另一侧关闭了一半。我会解决这个问题,给你一个更好的错误消息,但它仍然是一个错误;要么你的网络正在破坏你的MySQL连接,要么什么的。
您正在使用连接池吗?根据堆栈跟踪,您似乎只是在超时后对连接进行查询。可能是您持有非活动连接的时间过长,网络或MySQL服务器上的某些东西正在终止连接。
相关文章:
- Javascript连接元素,出现问题
- 在html中连接图像和描述时出现问题
- 将.schie Javascript函数连接到我的HTML时出现问题
- ASP.NET-连接html、javascript和CSS的问题
- NodeJs 套接字连接问题
- 使用JavaScript连接字符串有什么问题
- 检测 iframe 中的连接问题
- 以下jQuery字符串连接代码有什么问题
- 使用 sequelize ORM 连接到节点上的 Amazon RDS Postgres 数据库.js出现问题
- 加载资源时出现 OpenTok JS 连接超时问题
- JavaScript 谷歌地图折线 :连接所有给定的 GPS 位置时出现问题
- 使用 grunt requirejs 与单个大型缩小文件连接缓慢时加载问题
- Node 和 MySQL - 解决“连接过多”问题
- 实时连接小程序问题
- NodeJS MongoDB 连接字符串问题
- 使用IONIC的IOS没有网络连接功能问题
- Windows Live API连接问题
- LinkedIn API 连接问题
- webrtc通过websocket客户端/服务器连接问题
- 流程图问题连接条形图和线形图