0

这是我的数据库代码



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
}

我尝试在互联网上查找问题,但我仍然不知道为什么会出现此错误。

4

1 回答 1

0

就像评论里的人说的:

var con = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "",
  port: "889", 
});

如果您在同一端口上运行其他进程 SQL 将无法正常工作,那么端口号是否错误通常人们使用:

var con = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "",
  port: "3306", 
});
于 2020-11-29T21:40:50.073 回答