markoffden markoffden - 1 year ago 680
Node.js Question

Failed to connect to localhost:1433 - connect ECONNREFUSED

I'm trying to connect to my local MySql server from node.js/express application using

with following config:

// Database connection
var sql = require('mssql');
var config = {
user: 'db_user',
password: 'db_pass',
server: 'localhost',
database: 'project_db'
sql.connect(config, function (err) {
if (err) {

I get this error:

{ [ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED]
name: 'ConnectionError',
message: 'Failed to connect to localhost:1433 - connect ECONNREFUSED',
code: 'ESOCKET' }

I know I have to enable TCP/IP connections for my local MySql server, but I can not find how to do it on OSX El Capitan. There is nothing like control panel with settings. That's all available at System Preferences > MySql:
enter image description here
Any ideas how to fix this, guys? Thanks for trying to help.

Answer Source

mssql and mysql are two very different things... You should use the node-mysql or some other mysql client library if you are going to be running mysql on your dev machine

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'me',
  password : 'secret',
  database : 'my_db'


connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
  if (err) throw err;

  console.log('The solution is: ', rows[0].solution);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download