node-mysql错误:连接ECONNREFUSED [英] node-mysql error: connect ECONNREFUSED
问题描述
我正在尝试使用node-mysql在数据库服务器和客户端节点应用程序之间建立远程连接.
I'm trying to setup a remote connection between my database server and a client node app using node-mysql.
当我尝试连接到远程数据库时,出现此错误:
When I try to connect to the remote db, I get this error:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: connect ECONNREFUSED
at errnoException (net.js:646:11)
at Object.afterConnect [as oncomplete] (net.js:637:18)
(使用socketPort参数)可以正常连接到本地数据库.
Connecting to a local db works ok (with the socketPort parameter).
我可以使用PHP从我的计算机本地主机以及我拥有的另一台服务器连接到该远程数据库,因此我认为mysql conf没什么问题.
I can connect to this remote db with PHP from my computer localhost as well as another server I own so I don't think there's something wrong with mysql conf.
有关信息,nodejs与nginx一起运行,并且我已经设置了代理以使节点在端口80上工作,这可能是问题吗?
For info, nodejs is running with nginx and I've setup a proxy to make node work on port 80, maybe this is the issue?
如何检查?
谢谢.
编辑
这是我的代码,以防万一:
Here's my code, just in case:
var express = require('express');
var mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
debug: false,
host: '12.34.56.67',
user: 'user',
password: 'pass'
});
推荐答案
尝试使用mysql套接字:
Try using mysql socket:
var connection = mysql.createConnection({
user: 'user',
password: 'pass',
socketPath: 'mysql-socket-path', /*example: /Applications/MAMP/tmp/mysql/mysql.sock*/
database: 'dbname'
});
这篇关于node-mysql错误:连接ECONNREFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!