NodeJS中的MySQL错误:无法以root身份连接

时间:2017-12-18 01:49:11

标签: mysql node.js

我正在开发一个使用NodeJS(8.9.0 for Windows)和MySQL(5.7.0 for Windows)的小项目。操作系统是WIndows 10 64位。

我的问题很简单(缺乏细节),因为我缺乏Node的经验:
在我的mysql安装或NodeJS应用程序的mysql模块中,甚至在MySQL工作台的设置中,是这个异常的原因吗?我想设置(使用密码) :YES),可以在错误日志中看到NO,Node应用程序无需密码即可连接。 wh,但我不知道在哪里禁用它

这里的控制台日志除外:

    C:\Users\myPCAccount\git\sampleProject>node app.js
Environment: development
Configuring server
Configuring sequelize
Synchronising database
Configuring passport
Configuring express-server
Server listening on port 3000
Unhandled rejection SequelizeAccessDeniedError: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
    at Handshake._callback (C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:83:20)
    at Handshake.Sequence.end (C:\Users\myPCAccount\git\sampleProject\node_modules\mysql\lib\protocol\sequences\Sequence.js:88:24)
    at Handshake.ErrorPacket (C:\Users\myPCAccount\git\sampleProject\node_modules\mysql\lib\protocol\sequences\Handshake.js:132:8)
    at Protocol._parsePacket (C:\Users\myPCAccount\git\sampleProject\node_modules\mysql\lib\protocol\Protocol.js:279:23)
    at Parser.write (C:\Users\myPCAccount\git\sampleProject\node_modules\mysql\lib\protocol\Parser.js:76:12)
    at Protocol.write (C:\Users\myPCAccount\git\sampleProject\node_modules\mysql\lib\protocol\Protocol.js:39:16)
    at Socket.<anonymous> (C:\Users\myPCAccount\git\sampleProject\node_modules\mysql\lib\Connection.js:103:28)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:594:20)
From previous event:
    at ConnectionManager.connect (C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:55:10)
    at ConnectionManager.<anonymous> (C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\dialects\abstract\connection-manager.js:247:43)
From previous event:
    at Promise.then (C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\promise.js:21:17)
    at Model.sync (C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\model.js:993:6)
    at C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\sequelize.js:1014:20
From previous event:
    at Function.each (C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\promise.js:21:17)
    at C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\sequelize.js:1013:20
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
From previous event:
    at Promise.then (C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\promise.js:21:17)
    at Sequelize.sync (C:\Users\myPCAccount\git\sampleProject\node_modules\sequelize\lib\sequelize.js:1000:6)
    at module.exports (C:\Users\myPCAccount\git\sampleProject\config\sequelize.js:32:35)
    at Object.<anonymous> (C:\Users\myPCAccount\git\sampleProject\app.js:32:30)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

1 个答案:

答案 0 :(得分:0)

“使用密码:是”仅表示您的节点应用确实提供了密码。

“使用密码:否”表示您的Node应用程序未提供密码(或指定为''作为空密码)。这是否有效取决于您是否在MySQL服务器中创建了没有密码的用户。

出于安全原因,不建议创建一个空密码的MySQL用户 - 更不用说root用户了。除非您使用TLS证书而不是密码。