• Register
0 votes
977 views

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();

    }

);

 

6 5 3
7,540 points

1 Answer

0 votes

Solution :

I had faced the same issue, I fixed it by changing the just the password to empty string as follows:

var mytestsql = require('mytestsql');
var myconnection = mytestsql.createConnection({
    host: 'localhost',
    user: 'root',
    password: ''
});

 

9 7 4
38,600 points

Related questions

0 votes
1 answer 16 views
0 votes
1 answer 67 views
67 views
Problem : I am new to MySql. The problem started when I was unable to login to Mysql using my Mysql console. It is repeatedly asking me the password and now I am unable to remember my password. Can I change my password ? And now when I am trying to open my PhpMyAdmin ... WAMP and after that deleted all my related files and then reinstalled it .But it did not fix my issue. How can I fix the issue ?
asked Feb 26 mphil 2.3k points
0 votes
1 answer 56 views
0 votes
1 answer 31 views
31 views
Problem: I had installed MySQL on my linux server sometimes back now I forgot the password so I tried to change it using the ways I found online. What I did was as shown below: /etc/init.d/mysql stop mysqld_safe --skip-grant-tables & mysql --user root mysql SELECT * ... it still shows me below errors  "Access denied for user 'root'@'localhost' (using password: Yes)". How to fix above MYSql error?
asked Jul 14 Raphael Pacheco 4.9k points