简体   繁体   中英

Access Denied for MySql Connection in Nodejs

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

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

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',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM