node-mysql error: connect ECONNREFUSED

node cannot connect to mysql
error connect econnrefused 127.0 0.1 3306 adonis
sequelize connection refused error
heroku error connecting error: connect econnrefused 127.0 0.1 3306
digitalocean mysql econnrefused
unable to connect to the database connect econnrefused
sql connection in node js
node js mysql web application

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

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.js MySQL - Error: connect ECONNREFUSED, You need to add the value of socket path to the config object: socketPath: '/var/​run/mysqld/mysqld.sock'. In MAMP, you go to  I'm trying to use promise-mysql (node module) to connect to a MySQL instance, but it fails with ECONNREFUSED. Here's the entire error: { Error: connect ECONNREFUSED 172.18.0.6:3306 at Object.exports._errnoException (util.js:1018:11) at exports._excep

Should one still look for an answer:

Check your MySql server's configuration.

In my case running netstat -ln | grep mysql(as per Troubleshooting Problems Connecting to MySQL) revealed that my server is listening on the socket /tmp/mysql.sock so in createConnection's options I used socketPath: '/tmp/mysql.sock' instead of host: and port:

Error: connect ECONNREFUSED · Issue #874 · mysqljs/mysql · GitHub, Error: connect ECONNREFUSED is the error I get everything I try to connect to a mysql database using this npm install felixge/node-mysql. By setting the IP to 127.0.0.1 (which is the local loopback) that tells NR to attempt to connect to MySQL on the same machine. Try putting in the IP of the machine running MySQL and see what happens. anisha 27 July 2019 12:05 #5

Module does not work in Node.js 0.6 (was: ECONNREFUSED , I'm trying to connect to MySQL server in this way. var config = require('. connection.connect err { [Error: connect ECONNREFUSED] code:  Maybe it is the port 8443. node app.js enter, connect ECONNREFUSED. no, it's not the port. No password, no root, no port. What can solve this? OOhh, yes, I know, I should thinking about that. Maybe I need to put the project in root XAMPP root folder. No. connect ECONNREFUSED. 3 hours later. I need more music.

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

Can't connect to MySQL using Node.JS, JS but an error occured [Error : connect ECONNREFUSED] code I already created a droplet of MySQL and change my password after login  It is because your connection was refused trying to establish a TCP connection to port 3306 on localhost. The following is the mysql command you can use to verify connectivity (you must run it exactly as specified here):

Ok so I checked with node-mysql dev and it seems that it's not a node-mysql bug, but it was hard to investigate more.

Anyway, I found this lib which works, so I'll go with it.

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

Node.js with MySQL, two properties: err.code : A MySQL server error (e.g. '​ER_ACCESS_DENIED_ERROR'); A node.js error (e.g. 'ECONNREFUSED'); An internal error (e.g. var mysql = require('mysql'); var connection = mysql. @LoicAG ECONNREFUSED means that something is actively rejecting your TCP connection to db.domain.tld on port 3306. You can always try running this command from the machine that would run your node.js mysql client: nc -v -z db.domain.tld 3306.

Trying to connect Node.js to MySql database and having issues , Trying to connect Node.js to MySql database and having issues. if (err) throw err ^ Error: connect ECONNREFUSED 127.0.0.1:3306 at  Error: connect ECONNREFUSED or Error: connect ETIMEDOUT. Solution. Make sure your VPC Security groups have the right privileges, we'll go into detail below.

Node.JS/MySQL - Error: connect ECONNREFUSED, I'm trying to connect to a MySQL database with Node.JS and at first, it works. Then, kinda at random, it gives the following error: Error: connect  Hi there please help I have node-red running on a locally networked PI3. I want to connect MYSQL on an external ubuntu server running MYSQL. When i configure a MYSQL node with the MYSQL login details of the ubuntu server i get the message CONNECTION REFUSED The settings of the node are Host 160* Port 3306 User useronpi3 Password •••••••• Database DATABASENAME Timezone

How to resolve 'Unable to connect to MySQL server' issues in Ghost, Error: connect ECONNREFUSED 127.0.0.1:3306. If you're seeing this ECONNREFUSED error which refers to port 3306, this means that Ghost wasn't able to 

Comments
  • Can you get the error code that mysql sends to node-mysql ?
  • Yep it's: { [Error: connect ECONNREFUSED] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect', fatal: true }
  • I believe the plugin is not showing the errors properly. I'd send this to the plugin developers and see if they can show the Mysql error code and message. ECONNREFUSED doesn't say much, it could be several things.
  • I just did that, thanks for you help. I'll let you know if the plugin devs find something.
  • Firewalls cause connect timeouts. There was a firewall that issued refusals twenty years ago but it was rapidly recognized that is was a security breach, as it reveals the existence of the host and port. Your fourth point encapsulates both your second and third points.
  • I was having this exact problem and never managed to solve it. Switching to db-mysql for db stuff solved it.
  • Looks like node-mysql latest version fixed the issue. At least it works for me with v2.2.0