gpt4 book ai didi

javascript - 无法使用nodejs连接到mysql

转载 作者:行者123 更新时间:2023-12-01 00:00:00 25 4
gpt4 key购买 nike

我是 nodejs 的新手,在创建到数据库的连接时遇到了这个错误

C:\Users\devashis khandelwal\node_modules\mysql\lib\protocol\Parser.js:80 throw err; // Rethrow non-MySQL errors ^

Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'Root'@'localhost' (using password: YES) at Handshake.Sequence._packetToError (C:\Users\devashis khandelwal\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14) at Handshake.ErrorPacket (C:\Users\devashis khandelwal\node_modules\mysql\lib\protocol\sequences\Handshake.js:103:18) at Protocol._parsePacket (C:\Users\devashis khandelwal\node_modules\mysql\lib\protocol\Protocol.js:279:23) at Parser.write (C:\Users\devashis khandelwal\node_modules\mysql\lib\protocol\Parser.js:76:12) at Protocol.write (C:\Users\devashis khandelwal\node_modules\mysql\lib\protocol\Protocol.js:39:16) at Socket. (C:\Users\devashis khandelwal\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 (C:\Users\devashis khandelwal\node_modules\mysql\lib\protocol\Protocol.js:145:48) at Protocol.handshake (C:\Users\devashis khandelwal\node_modules\mysql\lib\protocol\Protocol.js:52:23) at Connection.connect (C:\Users\devashis khandelwal\node_modules\mysql\lib\Connection.js:130:18) at Object. (C:\Users\devashis khandelwal\node files\demo_db_connection.js:9:5) 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.runMain (module.js:604:10)

var mysql = require('mysql');

var con = mysql.createConnection({
host : 'localhost',
user : 'Root',
password : 'my_pass',
});

con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});

最佳答案

您正在连接用户Root,我相信它是root。您的错误显然是凭据错误。

关于javascript - 无法使用nodejs连接到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46432308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com