1
var mysql = require('mysql');

var client = mysql.createClient({
  user: 'myusername',
  password: 'mypassword',
});

client.query('USE mydb');

A simple setup like this using node's mysql is returning an ECONNREFUSED error, although the credentials are correct and permissions are updated. I have even used a different node module to successfully connect/query the database using the same credentials, but the syntax of this module is in my opinion far superior.

Anyone have an idea whats causing this to go wrong?

Error:

node.js:201 throw e; // process.nextTick error, or 'error' event on first tick
^
Error: connect ECONNREFUSED

majic bunnie
  • 1,395
  • 2
  • 10
  • 21

2 Answers2

2
In mysql.conf, comment skip-networking.
Ghostman
  • 6,042
  • 9
  • 34
  • 53
1

For creating the database you need to use the command CreateConnection and not createClient, make the necessary changes and that should work !

var mysql = require('mysql');

var client = mysql.createConnection({
  host: 'localhost',
  user: 'myusername',
  password: 'mypassword',
});

client.query('USE mydb');

Note that you have not mentioned which database you are accessing !

Devrath
  • 42,072
  • 54
  • 195
  • 297