This code works well on windows using nodejs and wamp but dont work on mac using mamp any idea why ? (the same username,password and db are used on both mac and pc !)
Im receiving this error Error: connect ECONNREFUSED
var mysql = require('mysql');
var TEST_DATABASE = 'krekib';
var TEST_TABLE = 'users';
var client = mysql.createClient({
user: 'root',
password: '12345',
});
client.query('USE '+TEST_DATABASE);
client.query(
'SELECT * FROM '+TEST_TABLE,
function selectCb(err, results, fields) {
if (err) {
throw err;
}
console.log(results);
console.log(fields);
client.end();
}
);
You probably need to specify your host and port. Check which port mysql is running in MAMP and add this.
var mysql = require('mysql');
var TEST_DATABASE = 'krekib';
var TEST_TABLE = 'users';
var client = mysql.createClient({
user: 'root',
password: '12345',
host: "127.0.0.1 or localhost, depends on your mysql user permissions",
port: "your port number in mamp",
});
Why would you connect to a database with JavaScript? It's really easy to find the JavaScript file and get your username + password.
Is the database running in Mamp?