I am trying to connect node js to MySQL database which is up and running according to the MySQL Workbench. However the usual create connection code template isn't working.
Any ideas as to why this is?
I have tried putting a function and error around the connection.connect()
part to see if it actually connects. But the terminal window comes up with the same error nonetheless:
Marcs-MacBook-Pro:npm-global marcwatts$ node index.js
Error while performing Query.
Do we think that it is connecting ok or does it not connect in the first place?
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '<hidden from stack overflow>',
database : 'songdata'
});
connection.connect();
connection.query('SELECT * from songdata2', function(err, rows, fields) {
if (!err)
console.log('The solution is: ', rows);
else
console.log('Error while performing Query.');
});
connection.end();
I just want to connect so I can learn how to write the code which takes each song and places its lyrics inside the Watson Tone analyzer and outputs the results in a new table in MySQL. Any advice on this part would be much appreciated too as I am new to web apps!