node.js 出现错误代码 Cannot enqueue Handshake after invoking quit
2017-10-25 19:44
585 查看
出现错误的原因是 数据库的连接对象被设计成一挂掉就无法重连。
但是我们还是希望数据库不用的时候end因为数据库的连接次数有限。
但是重新打开链接相对于一般的新增数据操作(insert)来说确实比较耗性能,约为新增数据操作(insert)的10-100倍,但是除非日处理数据千万级以上的应用,否则重新关闭打开数据库链接所带来的性能损耗不明显。
所以人数少的或者操作不频繁可以考虑用这种方式--连接之后不关闭,
如果你是在伺服web请求,你就不该在每次请求处理完时关掉连接了。服务器启动时创建一个连接,然后一直用connection/client对象查询就好。
解决方法
1.例如我的config.js的配置,因为使用该网页的人数不多,所以我采用了连接后不关闭的做法
//数据库配置
//连接数据库
var mysql = require('mysql');
var connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "123456",
database:'zxd_data'
});
connection.connect();
function selectfun(username,password,callback){
connection.query('select password from user_info where username="'+username+'"',function(err,results){
if(err) throw err;
callback(results);
});
}
function getSql(sql,callback){
connection.query(sql,function(err,results){
if(err) throw err;
console.log('从数据库中提取数据');
callback(results);
});
}
2.
https://stackoverflow.com/questions/14087924/cannot-enqueue-handshake-after-invoking-quit#
参考
http://www.cnblogs.com/LoveJenny/archive/2011/08/09/2131664.html#!comments
但是我们还是希望数据库不用的时候end因为数据库的连接次数有限。
但是重新打开链接相对于一般的新增数据操作(insert)来说确实比较耗性能,约为新增数据操作(insert)的10-100倍,但是除非日处理数据千万级以上的应用,否则重新关闭打开数据库链接所带来的性能损耗不明显。
所以人数少的或者操作不频繁可以考虑用这种方式--连接之后不关闭,
如果你是在伺服web请求,你就不该在每次请求处理完时关掉连接了。服务器启动时创建一个连接,然后一直用connection/client对象查询就好。
解决方法
1.例如我的config.js的配置,因为使用该网页的人数不多,所以我采用了连接后不关闭的做法
//数据库配置
//连接数据库
var mysql = require('mysql');
var connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "123456",
database:'zxd_data'
});
connection.connect();
function selectfun(username,password,callback){
connection.query('select password from user_info where username="'+username+'"',function(err,results){
if(err) throw err;
callback(results);
});
}
function getSql(sql,callback){
connection.query(sql,function(err,results){
if(err) throw err;
console.log('从数据库中提取数据');
callback(results);
});
}
2.
https://stackoverflow.com/questions/14087924/cannot-enqueue-handshake-after-invoking-quit#
参考
http://www.cnblogs.com/LoveJenny/archive/2011/08/09/2131664.html#!comments
相关文章推荐
- NodeJS连接MySQL出现Cannot enqueue Handshake after invoking quit.
- node.js的"Cannot enqueue Handshake after invoking quit"错误
- 连接数据库出现Error: Cannot enqueue Handshake after already enqueuing a Handshake.
- node.js在执行js文件时出现SystaxError:Unexpected token LILEGAL的错误
- NRPE出现:CHECK_NRPE: Error - Could not complete SSL handshake.错误!
- eclipse出现 Some characters cannot be mapped using "GBK" character encoding 错误代码的解决办法
- [乐意黎原创]Node.js 出现Error:Cannot find runtime 'node' on PATH - Visual Studio Code中的解决办法
- node.js开发错误——TypeError: Cannot set property 'XXX' of undefined
- npm安装时出现错误解决办法及mac下升级node.js
- 用MVC结构写web小程序时出现“ Cannot forward after response has been committed”的错误
- 页面js 出现 “不能执行已经释放的Script代码”错误
- 今天写HQL出现了一个低级错误,将from 写错成form了 出现java.lang.IllegalArgumentException: node to traverse cannot be null!
- hibernate 中,出现了错误 "node to traverse cannot be null!" 如何改正
- NRPE出现:CHECK_NRPE: Error - Could not complete SSL handshake.错误!
- node.js安装npm模块出现错误
- node.js安装npm模块出现错误
- Win7,Win8安装ArcGIS软件或Node.js等安装包出现2503错误的解决方法
- git bash下出现错误Error: Cannot find module 'git目录/node_modules/git包/bin/git包'
- knockout.js(js)代码在IE中出现“意外地调用了方法或属性”的错误
- 不通过 您的代码已保存 编译错误:您提交的代码无法完成编译 ./TreeLevel.java:37: error: cannot find symbol node.next=new ListNode(