0

I'm trying to connect my mysql database but i can not i got error that : Error: connect ECONNREFUSED 127.0.0.1:8889

My code :

var express = require("express");
var app = express();

var mysql = require("mysql");
var bodyParser = require("body-parser");

app.use(bodyParser.json({type:'application/json'}));
app.use(bodyParser.urlencoded({extended:true}));

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

var server = app.listen(8000,function(){console.log("localhost successfull");
    var host = server.address().address
    var port = server.address().port
});

con.connect(function(error){
    if(error) console.log("error : "+error);
    else console.log("database successfull");
});

and i got this output :
localhost successfull
error : Error: connect ECONNREFUSED 127.0.0.1:8889

I also checked my MAMMP settings , everything is okay

a screenshoot from my work

mammp settings

ahmetbcakici
  • 363
  • 6
  • 17
  • have you tried replacing `localhost` with `127.0.0.1` in your `mysql.createConnection` object? – dusthaines Sep 23 '19 at 15:57
  • yes and same error again , nothing changed – ahmetbcakici Sep 23 '19 at 15:59
  • Probably an issue of port mapping as the user below notes, or you may have more than one instance of `mysqld` running. See this question for details on diagnosis and resolution: https://stackoverflow.com/a/9476162/1720873 – dusthaines Sep 23 '19 at 17:32

1 Answers1

1

I execute your code like:: it worked I think issue is with you mysql connection

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

execution

  • oh okay okay i check my mammp mysql port again from mysql preferences , there is writing 3306 i copied your code and executing , it worked! thank you so much problem was about my mammp - mysql port – ahmetbcakici Sep 24 '19 at 14:45