请我在nodejs中使用expressjs。我实际上是nodejs的新手。
我尝试使用我通常的凭据连接到mysql但是我收到以下错误。
请帮帮我。谢谢。
"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
答案 0 :(得分:3)
如readme所示,您应使用user
代替username
:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'password',
database : 'db_name'
})
connection.connect();
答案 1 :(得分:0)
用户 :和 密码 :请使用小写字母将它们全部写成小写提到的标题(用户名和密码)变为大写,将显示错误 'ER_ACCESS_DENIED_ERROR:对用户“ @'localhost”的访问被拒绝(使用密码:是) 相反,主机和数据库不区分大小写
Host : 'localhost',
user : 'user_username',// if you create a user otherwise use 'root'
Database : 'the database',
password : 'your password',