Heroku应用程序上的远程mysql数据库 [英] Remote mysql database on Heroku app

查看:150
本文介绍了Heroku应用程序上的远程mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用我的个人web服务器中的mysql数据库而不是heroku的数据库吗?

Can I use mysql database from my personal web server instead of heroku's database?

我这样配置我的生产数据库:

I configured my production database like this:

production:
    adapter: mysql2
    database: somedatabase
    username: someusername
    password: somepassword
    host: 1.1.1.1:1234

但是,这不起作用,我的应用程序仍然使用heroku的共享数据库。

But, this doesn't work, my app still uses heroku's shared database.

推荐答案

这是旧的,但如果有人在寻找答案时出现问题,比使用gem更容易。只需提供一个 DATABASE_URL SHARED_DATABASE_URL (不知道是否需要第二个)。数据库的URL格式是 adapter:// username:password @ hostname:port / database ,例如,你可以这样做:

This is old but in case anyone drops around looking for an answer, it's much easier than using the gem. Just provide a DATABASE_URL and SHARED_DATABASE_URL (not sure if the second is needed). The database url format is adapter://username:password@hostname:port/database, so for example, you would do:

heroku config:add DATABASE_URL=mysql://etok:somepassword@<your-server>:3306/etok
heroku config:add SHARED_DATABASE_URL=mysql://etok:somepassword@79.101.41.213:3306/etok

然后重新部署您的应用。它会读你的 DATABASE_URL 并从中生成database.yml。默认端口已经是3306,所以在你的情况下,它不需要在URL中。在部署时,您可能会注意到它会生成您的database.yml文件:

Then re-deploy your app. It will read your DATABASE_URL and generate the database.yml from that. The default port is already 3306 so it's not needed in the url in your case. When you deploy, you may notice that it generates your database.yml:

-----> Writing config/database.yml to read from DATABASE_URL

然后设置(只要您的服务器接受来自您的heroku主机的连接。

Then you're set (as long as your server accepts connections from your heroku host.

这篇关于Heroku应用程序上的远程mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆