user2000008 user2000008 - 1 year ago 132
MySQL Question

db URL works in MySQL Workbench, but not node.js (getaddrinfo ENOTFOUND)

I've set up a MySQL db in Heroku, and successfully connected to it via MySQL Workbench.

I've been using felixge's

plugin to try and connect to it from my app (written in coffeescript), set up the connection as follows:

db = mysql.createConnection({
host: ''
user: 'mysn'
password: 'mypwd'

Unfortunately I'm getting an
Error: getaddrinfo ENOTFOUND
in the console and the app crashes. I know the error's from this block of code because removing it works fine. Preliminary googling implied that this error is because the db URL is wrong, but it's copy pasted from what I put into MySQL Workbench and that's working fine. I've manually ran this chunk of code through js2coffee and it's being transpiled correctly, so it's not CS screwing up the object or anything, either.

Answer Source

Even though the information was all exactly the same, I got it to connect successfully and run a query by passing the information as a string instead of an object.

db = mysql.createConnection('mysql://')

I'm not marking this as the answer because I'd still like to know why passing the information as an object was failing.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download