简体   繁体   English

Node-MySQL(felixge)连接问题

[英]Node-MySQL (felixge) connection problems

I'm running Node.js 4.1 with Node-Mysql on an Ubuntu 10.04 LTS VM. 我在Ubuntu 10.04 LTS VM上运行带有Node-Mysql的 Node.js 4.1。 I'm having some weird problems, however, and I'm not sure what's causing it. 然而,我遇到了一些奇怪的问题,而且我不确定是什么导致了它。

I occasionally cannot connect to the database, and other times it works fine. 我偶尔无法连接到数据库,有时它工作正常。 When I can't connect I see the connection popup in the connections on the mysql side, with the user as "unauthenticated" and the state as "reading from net" but it goes away after a few seconds. 当我无法连接时,我在mysql端的连接中看到连接弹出窗口,用户为“unauthenticated”,状态为“从网络读取”,但几秒后它就会消失。 The .connect() callback never fires and I'm not sure where to go from here. .connect()回调永远不会触发,我不知道从哪里开始。

I am using port forwarding from the host machine to the vm, for 22 for SSH and 80 for http requests, but other than that everything is normal. 我正在使用从主机到vm的端口转发,22用于SSH,80用于http请求,但除此之外一切正常。 The host on mysql shows up as the host machine, and not the VM, although it does that even for successful connects. mysql上的主机显示为主机,而不是VM,尽管即使成功连接也是如此。

Not sure of the significance but the connection holds in TIME_WAIT on the VM, and the local address:port is different than what MySQL has, for successfull connections as well. 不确定重要性,但连接在VM上的TIME_WAIT中保持,并且本地地址:端口与MySQL不同,也用于成功连接。

Are you using the latest version (0.9.2)? 您使用的是最新版本(0.9.2)吗? If you are, you no longer use .connect() . 如果是,则不再使用.connect()

https://github.com/felixge/node-mysql/wiki/Upgrading-to-0.9.2+ https://github.com/felixge/node-mysql/wiki/Upgrading-to-0.9.2+

So instead of: 所以代替:

var client = require('mysql').Client();
client.connect();
client.query('SELECT 1', function() {
});

You now have to write: 你现在必须写:

var client = require('mysql').createClient();
client.query('SELECT 1', function() {
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM