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

128 views Asked by At

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.

1

There are 1 answers

0
Yunfei Chen On

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