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

1

2 Answers 2

2
In mysql.conf, comment skip-networking.
Sign up to request clarification or add additional context in comments.

Comments

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 !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.