Node-mysql error: enable ECONNREFUSED

I am trying to establish a remote connection between my database server and the node client application using node-mysql.

When I try to connect to a 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 local db is working fine (with socketPort parameter).

I can connect to this remote db with PHP from my localhost computer, as well as with another server that I have, so I don’t think that something is wrong with mysql conf.

For information, nodejs works with nginx, and I installed a proxy server to make node work on port 80, maybe this is a problem?

How can I check this?

Thank.

EDIT

Here is 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'
});
+5
7

mysql socket:

var connection = mysql.createConnection({
    user: 'user',
    password: 'pass',
    socketPath: 'mysql-socket-path', /*example: /Applications/MAMP/tmp/mysql/mysql.sock*/
    database: 'dbname'
});
+17

:

MySql.

netstat -ln | grep mysql ( , MySQL) , /tmp/mysql.sock createConnection socketPath: '/tmp/mysql.sock' host: port:

+7

, MySQL host:port. errno.h, ECONNREFUSED - , - , :

  • , iptables,
  • ,

MySQL- 0.0.0.0 , 127.0.0.1, ; .

node-mysql, stacktrace, net.js.

+2

, node -mysql dev, , node -mysql, .

, , , .

https://github.com/mariano/node-db-mysql

+1

. , createConnection.

, : netstat -tlnp

mysqld .

0

: 3306, .

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();
0

Use the command: start yarn start and DO NOT use: cd / folderX && start yarn start

0
source

Source: https://habr.com/ru/post/1535448/


All Articles