Search code examples
mysqlnode.jsherokunode-mysql

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 node-mysql plugin to try and connect to it from my app (written in coffeescript), set up the connection as follows:

db = mysql.createConnection({
    host: 'server-name.cleardb.com/heroku_randomletters?reconnect=true'
    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.


Solution

  • 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://mysn:mypwd@server-name.cleardb.com/heroku_randomletters?reconnect=true')
    

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