这是我的数据库代码
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
port: "889",
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
con.query("CREATE DATABASE mydb", function (err, result) {
if (err) throw err;
console.log("Database created");
});
});
这是我尝试在终端窗口中运行它时遇到的错误
if (err) throw err;
^
Error: connect ECONNREFUSED 127.0.0.1:889
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
--------------------
at Protocol._enqueue (C:\Users\Amman\dunder-mifflin\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\Amman\dunder-mifflin\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Users\Amman\dunder-mifflin\node_modules\mysql\lib\Connection.js:116:18)
at Object.<anonymous> (C:\Users\Amman\dunder-mifflin\src\database\database.js:11:5)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 889,
fatal: true
}
我尝试在互联网上查找问题,但我仍然不知道为什么会出现此错误。