Heroku 应用程序上的远程 mysql 数据库

编程入门 行业动态 更新时间:2024-10-27 14:25:20
本文介绍了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 数据库

本文发布于:2023-10-17 12:48:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   数据库   Heroku   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!