Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

errorError: getaddrinfo ENOTFOUND - mysql

Tags:

json

node.js

I'm running a server on c9.io using Node.js and trying to connect to Mysql I guess I get this error:

Error: getaddrinfo ENOTFOUND

because the connection to the db is wrong.

I'm using this:

var connection = mysql.createConnection({
    host: "REMOTE_ADDR",
    user: "MYUSERNAME", // this is replaced by my username
    database: "c9",
    port: 3306
});

Any idea what's wrong?

Thanks!

like image 710
Nathan Avatar asked Aug 27 '14 07:08

Nathan


1 Answers

This code works for me.

var mysql = require('mysql');

var con = mysql.createConnection({
    host: '127.0.0.1',
    port: '3306',
    user: 'yourUsername',
    password: '**********'
});

con.connect(function(err){
    if(err) throw err;
    console.log('connected!');
});

the host and port name find them in your mysql server. in-place of '127.0.0.1' you can use 'localhost'

like image 191
daniel ernest Avatar answered Sep 21 '22 17:09

daniel ernest