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

编程入门 行业动态 更新时间:2024-10-27 12:31:07
本文介绍了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:50,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   数据库   Heroku   mysql

发布评论

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

>www.elefans.com

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