3

I have created a free instance of Heroku cleardb instance for my app. I set the database URL as:

heroku config:set DATABASE_URL='mysql://user:pass@us-cdbr-iron-east-03.cleardb.net/heroku_database?reconnect=true'

I'm trying to connect using a Go app. But when I try to access my application, it gives the following mysql error:

default addr for network 'us-cdbr-iron-east-03.cleardb.net' unknown

I tried to set the database url with protocol and port as well:

heroku config:set DATABASE_URL='mysql://user:pass@tcp(us-cdbr-iron-east-03.cleardb.net:3306)/heroku__database?reconnect=true'

This changes the errror to:

Access denied for user

which i'm guessing is because direct access to port is disallowed. Does anybody know what is the issue here?

abhink
  • 8,740
  • 1
  • 36
  • 48

1 Answers1

7

This is a Go specific problem. Three changes are required:

  1. Go's sql.Open already takes scheme as its first parameter so it needs to be stripped off of DATABASE_URL.
  2. Connection string shouldn't have any query parameters (remove ?reconnect=true).
  3. Protocol (tcp) and port (3306 for MySQL) number are required.

Thus final database URL would be:

DATABASE_URL='user:pass@tcp(us-cdbr-iron-east-03.cleardb.net:3306)/your_heroku_database'
abhink
  • 8,740
  • 1
  • 36
  • 48