简体   繁体   中英

I get this error message when I try to test run my MySQL database

this is my database code



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");
  });  
});

and this is the error I get when trying to run it in my terminal window

  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
}

I tried looking up problems on the internet but I still don't know why I'm getting this error.

Like the person in the comments said:

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

Is the wrong port number if you have other processes running on the same port SQL will not work usually people use:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM