node-mysql error: connect ECONNREFUSED

2019-06-21 03:38发布

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)

Connecting to a local db works ok (with the socketPort parameter).

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.

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?

How can I check that?

Thanks.

EDIT

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'
});

7条回答
相关推荐>>
2楼-- · 2019-06-21 04:17

I added port:3306, that solved the issue .

var connection = mysql.createConnection
    ({
        user: 'root',
        password: 'root',
        server: 'localhost',
    port:3306,
        database: 'abcd',
        insecureAuth: true,
        dialect: 'mysql',   
        multipleStatements: true,
        pool: {
            max: 5,
            min: 0,
            acquire: 30000,
            idle: 10000
        }
    });

    connection.connect();
查看更多
登录 后发表回答