Reputation: 1405
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
Upvotes: 1
Views: 1012
Reputation: 42854
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 !
Upvotes: 1