connect ECONNREFUSED using windows WSL

Viewed 611

I installed nodejs through the WSL of windows 10, but any connection to the database made by the WSL terminal and refused.

The code used for testing

var mysql = require('mysql');

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

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

the error that always occurs

/mnt/d/Projetos/EstudoNode/teste.js:11
  if (err) throw err;
           ^

Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
    --------------------
    at Protocol._enqueue (/mnt/d/Projetos/EstudoNode/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/mnt/d/Projetos/EstudoNode/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/mnt/d/Projetos/EstudoNode/node_modules/mysql/lib/Connection.js:116:18)      
    at Object.<anonymous> (/mnt/d/Projetos/EstudoNode/teste.js:10:5)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3306,
  fatal: true
}

What can be done to connect mysql using WSL?

0 Answers
Related