Using sequel pro I have created a database called test
. It has one table called users
. In that table there is one user -> id=1, name=Phantom
.
I have installed the mysql
node module
When I run the code below I get The solution is: undefined
.
Can anyone advise how I can connect to database and show the users?
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost:8889',
user : 'root',
password : 'root',
database : 'test'
});
connection.connect();
connection.query('SELECT * from users', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows);
});
connection.end();
It shows the following error :
Error: connect ETIMEDOUT at Connection._handleConnectTimeout (/Users/fitz035/Desktop/sony/presave/node_modules/mysql/lib/Connection.js:425:13)
I am running the db through MAMP. These are the db settings :
Host: localhost
Port: 8889
User: root
Password: root
Socket: /Applications/MAMP/tmp/mysql/mysql.sock
err
parameter in the callback to see, what went wrong. From your code I guess, the connection was closed, before the actual query went through. – Sirko