0

please i'm using expressjs in nodejs. Am actually new to nodejs.

Am trying to connect to mysql with the my usual credentials but i get the following errors.

Please help me out. Thank you.

"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" bin\www
Tue, 08 Dec 2015 21:39:57 GMT NodeApp:server Listening on port 3306
c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Parser.js:82
        throw err;
        ^

Error: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: YES)
    at Handshake.Sequence._packetToError (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\sequences\Sequence.js:48:14)
    at Handshake.ErrorPacket (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\sequences\Handshake.js:101:18)
    at Protocol._parsePacket (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:274:23)
    at Parser.write (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Parser.js:77:12)
    at Protocol.write (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\Connection.js:96:28)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    --------------------
    at Protocol._enqueue (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:135:48)
    at Protocol.handshake (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:52:41)
    at Connection.connect (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\Connection.js:123:18)
    at Object.<anonymous> (c:\Users\John\IdeaProjects\NodeApp\routes\about.js:16:12)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)

Process finished with exit code 1
2
  • Please show the portion of your code that connects to the DB - make sure you do not include any real password data. Commented Dec 8, 2015 at 23:33
  • var mysql = require('mysql'); var connection = mysql.createConnection({ host : 'localhost', username : 'root', password : 'password', database : 'db_name' }) connection.connect(); Commented Dec 11, 2015 at 11:25

2 Answers 2

6

As shown in the readme you should use user instead of username:

var mysql = require('mysql');

var connection = mysql.createConnection({
    host : 'localhost',
    user : 'root',
    password : 'password',
    database : 'db_name'
})

connection.connect();
Sign up to request clarification or add additional context in comments.

1 Comment

I spent 2 hours looking for answer and realize my username should be user
0

for user : and password: please write them all in small letter if any of the letter of the mentioned captions( user and password) becomes uppercase it will display the error 'ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: YES)' on the contrary, Host and database is not case sensitive

Host     : 'localhost',
user     : 'user_username',// if you create a user otherwise use 'root'
Database : 'the database',
password : 'your password',

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.