Heroku cleardb连接的默认地址为未知网络。

huangapple go评论87阅读模式
英文:

Heroku cleardb connection default addr for network unknown

问题

我已经为我的应用程序创建了一个免费的Heroku cleardb实例。我将数据库URL设置为:

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

我正在尝试使用Go应用程序进行连接。但是当我尝试访问我的应用程序时,它显示以下mysql错误:

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

我尝试使用协议和端口设置数据库URL:

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

这将错误更改为:

Access denied for user

我猜测这是因为禁止直接访问端口。有人知道这里的问题是什么吗?

英文:

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?

答案1

得分: 7

这是一个特定于Go的问题。需要进行三个更改:

  1. Gosql.Open函数已经将协议作为其第一个参数,因此需要从DATABASE_URL中去掉它。
  2. 连接字符串不应包含任何查询参数(删除?reconnect=true)。
  3. 协议(tcp)和端口(MySQL的3306)是必需的。

因此,最终的数据库URL应为:

DATABASE_URL='user:pass@tcp(us-cdbr-iron-east-03.cleardb.net:3306)/your_heroku_database'
英文:

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'

huangapple
  • 本文由 发表于 2017年4月23日 01:06:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/43562091.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定