2017-12-18 122 views
0

我正在使用NodeJS(8.9.0 for Windows)和MySQL(5.7.0 for Windows)的小型項目。操作系統是Windows 10 64位。NodeJS中的MySQL錯誤:無法以root身份連接

我的問題非常簡單(在缺乏細節方面),由於我與節點缺乏經驗:
這是例外的在我的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 

回答

0

「使用密碼:YES」只意味着你的節點應用並提供密碼。

「使用密碼:否」表示您的Node應用程序未提供密碼(或指定''作爲空密碼)。這是否會起作用取決於您是否在MySQL服務器中創建了沒有密碼的用戶。

爲安全起見,建議不要使用空密碼創建MySQL用戶 - 更不用說root用戶。除非您使用TLS證書而不是密碼。