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

查看:30
本文介绍了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_URLSHARED_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天全站免登陆