errorError: getaddrinfo ENOTFOUND - mysql

I'm running a server on c9.io using node.js and trying to connect to Mysql I guess I get this error "errorError: 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!

I know it's been a while since this was asked but I spent the better part of today trying to fix this. What to check for:

Within your nodejs source:

  • Try it without the 'port' option unless on your db VM, MySQL is listening on a port besides 3306. I had this option specified but had connection problems until I removed it. And 3306 is already the default value for the option anyway.
  • Try it with the actual host IP in the host 'option'. I was using an actual domain name and, more often than not, node-mysql would throw the same exact "errorError: getaddrinfo ENOTFOUND" When I used the IP address, no more errors. Also, I did not get this error while on Ubuntu instances in AWS. As soon as I switched over to Ubuntu VMs in Azure, I got the problem.
  • Set the "debug" connection option to true which will give you a verbose trace of what's happening during the connection

On your db VM/Box/Instance:

  • Ensure that MySQL is listening on the right port
  • If you're seeing the error when trying to make concurrent connections using a pool, check that your max_connections and max_user_connections haven't been changed from the default settings in my.conf
  • Monitor "SHOW PROCESSLIST;" in MySQL to see if you see any issues there