我試圖將我的項目連接到MySQL並使用XAMMP登錄頁面。Nodejs無法使用快遞連接到MySQL
我無法連接到MySQL
我的代碼:
var mysql=require('mysql');
var connection=mysql.createConnection({
host:'127.0.0.1',
port:'3307',
user:'root',
password:'1234',
database:'db'
});
connection.connect(function(error){
if(!!error){
console.log(error);
}else{
console.log('Connected!:)');
}
})
錯誤運行節點服務器後
{ Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
at Handshake.Sequence._packetToError (D:\db\database\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (D:\db\database\node_modules\mysql\lib\protocol\sequences\Handshake.js:103:18)
at Protocol._parsePacket (D:\db\database\node_modules\mysql\lib\protocol\Protocol.js:280:23)
at Parser.write (D:\db\database\node_modules\mysql\lib\protocol\Parser.js:75:12)
at Protocol.write (D:\db\database\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (D:\db\database\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
--------------------
at Protocol._enqueue (D:\db\database\node_modules\mysql\lib\protocol\Protocol.js:141:48)
at Protocol.handshake (D:\db\database\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (D:\db\database\node_modules\mysql\lib\Connection.js:130:18)
at Object.<anonymous> (D:\db\database\config\express.js:15:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000',
fatal: true }
**我想知道如何插入或從數據庫中選擇項目中的另一個js文件。我可以在控制器文件WIRTE呢?**
Update解決方案!: - 這個問題是因爲XAMMP端口和MySQL服務器端口不匹配。 它通過config將my.ini文件中的xammp MSQL端口解析爲3306(默認)
嘗試使用'localhost'而不是'127.0.0.1'',並且通過手動登錄來確保用戶名和密碼正確MySQL服務器。 –
嘗試仍然得到相同的錯誤。 – patppd