英文:
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
的问题。需要进行三个更改:
Go
的sql.Open
函数已经将协议作为其第一个参数,因此需要从DATABASE_URL
中去掉它。- 连接字符串不应包含任何查询参数(删除
?reconnect=true
)。 - 协议(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:
Go
'ssql.Open
already takes scheme as its first parameter so it needs to be stripped off ofDATABASE_URL
.- Connection string shouldn't have any query parameters (remove
?reconnect=true
). - 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'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论