Problem :
I am new to NodeJS and trying to connect to mySQL through the NodeJS file, however I am facing the below error :
{ Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
at Handshake.Sequence._packetToError (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/protocol/sequences/Sequence.js:40:14)
at Handshake.ErrorPacket (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/protocol/sequences/Handshake.js:77:18)
at Protocol._parsePacket (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/protocol/Protocol.js:297:24)
at Parser.write (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/protocol/Parser.js:72:12)
at Protocol.write (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/protocol/Protocol.js:47:16)
at Socket.ondata (_stream_readable.js:655:20)
at emitOne (events.js:201:20)
at Socket.emit (events.js:288:7)
at readableAddChunk (_stream_readable.js:276:18)
at Socket.Readable.push (_stream_readable.js:234:10)
--------------------
at Protocol._enqueue (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/protocol/Protocol.js:210:26)
at Protocol.handshake (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at Connection.connect (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/Connection.js:91:18)
at Connection._implyConnect (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/Connection.js:322:10)
at Connection.query (/home/alecxe/Node/mySqlTest/node_modules/mysql/lib/Connection.js:237:8)
at Object.<anonymous> (/home/alecxe/Node/mySqlTest/index.js:21:12)
at Module._compile (module.js:670:32)
at Object.Module._extensions..js (module.js:679:10)
at Module.load (module.js:587:32)
at tryModuleLoad (module.js:546:12)
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000',
fatal: true }
I am facing this error when running my javascript. I am using MySQL 5.7.16 on my Ubuntu 16.04.1 on a VM. Not sure if my VM makes a difference here.
Please find below my Javascript code :
'use strict'; var mytestsql = require('mytestsql');
var myconnection = mytestsql.createConnection({
host: 'localhost',
user: 'root',
password: 'password'
});
myconnection.query(
'SELECT "foo" AS first_field, "bar" AS second_field',
function(err, results, fields) {
console.log(err);
console.log(results);
myconnection.end();
}
);