Heroku 帮助部署使用 Mysql 数据库的 Rails 应用程序
我正在尝试部署一个使用 Mysql 的 Rails 应用程序,
我已经:
创建了一个 Heroku 应用程序并将我的应用程序推送到了 heroku。
我已添加 Amazon RDS 我已创建一个 Amazon RDS 数据库实例。 我的 Heroku Amazon RDS 数据库 URL 为:mysql://mysusername:[电子邮件受保护]/mydatabasename
我的 Amazon RDS 数据库安全组设置为默认值
- 我尝试推送本地数据库,但出现以下错误 Heroku 帮助 Amazon RDS Rails 推送数据库错误
我做错了什么?
我的 Rdshostname 是什么?它是亚马逊端点吗?
I am trying to deploy a Rails app that uses Mysql
I have:
Created a Heroku app and have pushed my app to heroku.
I have added Amazon RDS I have created a Amazon RDS database instance.
My Heroku Amazon RDS Database URL is: mysql://mysusername:[email protected]/mydatabasename
My Amazon RDS DB Security Group is set to default
- I have tried to push my local database but get the following error Heroku help Amazon RDS rails push database error
What am I doing wrong ?
What is my Rdshostname? Is it the Amazon endpoint?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只想首先说我感受到你的痛苦。我最近是 Rails 3 + Heroku + Amazon RDS 的新手。但是,今晚我解决了这个问题,并立即在 Stack Overflow 上让其他遇到问题的人知道如何解决。我稍后会在博客上介绍它。
您可能会跳过其中的一些内容,但我会尽力在此处提供全面的答复,包括您需要采取的步骤以及我遇到的问题和问题。
问题#1: heroku 无法安装 mysql2 gem,并出现以下错误:
解决方案: 我几乎总是使用 PostgreSQL 来处理我正在处理的任何要求较高的任务以及沙箱和实验,我只需使用 SQLite3 即可快速进出。真正的问题是我没有在本地计算机上运行 MySQL。当我回来并尝试在本地运行
bundle install
时,gem 安装自然会失败,因为它找不到 mysql 库。我确信有办法解决这个问题,但我只是硬着头皮在本地安装了mysql。之后,我可以毫无问题地运行bundle install
。另外,git push heroku master
将应用程序推送到 Heroku,没有失败:问题 #2: 即使在安装了 mysql2 gem 后,我的应用程序也卡住了。
heroku 日志
透露:什么?我刚刚将其添加到我的 gemfile 中,提交并成功推送!我真的以为有人在跟我开一个下流的玩笑。一些研究和摆弄发现
heroku rake db:migrate
正在返回:解决方案:我使用
gem uninstall mysql2
卸载了mysql2 gem,然后将我的 gemfile 中的行修改为:这安装了 mysql2 gem 的 0.2.7 版本,它也成功安装在 Heroku 上。
问题#3:安装正确版本的 mysql2 gem 后,
heroku rake db:migrate
仍然返回相同的错误:好的,所以我做了更多研究,发现此帖子,它基本上告诉我:该适配器尝试使用“mysql”适配器而不是“mysql2”适配器。
解决方案:解决这个问题的方法是在
heroku config
中手动设置DATABASE_URL
以使用mysql2://
通过执行以下操作:(您可以通过单击您正在使用的数据库在 AWS 配置面板中找到此 URL 的“dbInstanceName.hostname.us-east-1.amazonaws.com”部分)
这必须使用以下命令来完成line 工具,并且无法使用 Web 控制面板上的 RDS 附加 GUI 进行添加,因为 Heroku 不会接受它作为有效的数据库 URL。
陷阱#4:不正确的安全配置不会返回信息性或有用的错误。
解决方案:确保您已将安全组添加到 RDS 配置中,以允许 Heroku 访问您的 RDS 实例,并将该安全组添加到您的实例中。如需执行此操作的 CLI 帮助,您可以查看 Heroku 上的 RDS 文档 或登录到 AWS 控制台并执行以下操作此:
因此,回顾一下,如果您已经:
您现在应该能够。将 RDS 与 Heroku 上的 Rails 3 应用程序一起使用:)
I just wanted to first say that I feel your pain. I was recently a complete newbie to Rails 3 + Heroku + Amazon RDS. But, tonight I conquered the problem and immediately got on Stack Overflow to let others who were having issues know how. I'll blog about it later.
Some of this, you might skip, but I'll try to be comprehensive in my response here, including steps you'll need to take as well as gotchas and issues I encountered as well.
Gotcha #1: heroku fails to install mysql2 gem with the following error:
Solution: I almost always use PostgreSQL for anything demanding I am working on and for sandboxes and experiments, I just use SQLite3 to get in and out fast. The real issue was that I wasn't running MySQL on my local machine. When I came back and tried to run the
bundle install
locally, naturally the gem install failed because it could not find the mysql libraries. I'm sure there is a way around this, but I just bit the bullet and installed mysql locally. Afterwards, I was able to runbundle install
with no problem. Also,git push heroku master
pushed the application to Heroku with no failure:Gotcha #2: My application choked, even after installing the mysql2 gem.
heroku logs
revealed:What? I just added that to my gemfile, committed it and pushed it sucessfully! I really thought someone was playing a nasty joke on me. A little research and fiddling revealed that a
heroku rake db:migrate
was returning:Solution: I uninstalled the mysql2 gem with
gem uninstall mysql2
and then modified the line in my gemfile to read:This installed the 0.2.7 version of the mysql2 gem, which also installed on Heroku sucessfully.
Gotcha #3: After installing the correct version of the mysql2 gem, a
heroku rake db:migrate
still returned the same error:Okay, so I did some more research and found this thread, which basically told me that the adapter was trying to use the "mysql" adapter instead of the "mysql2" adapter.
Solution: The way around this one is to manually set the
DATABASE_URL
inheroku config
to usemysql2://
by doing this:(you can find the "dbInstanceName.hostname.us-east-1.amazonaws.com" portion of this url in your AWS config panel by clicking on the database you are using)
This has to be done using the command line tool, and cannot be added using the RDS Add-on GUI on the web control panel, because Heroku won't accept it as a valid db URL there.
Gotcha #4: Incorrect security configurations will not return informative or useful errors.
Solution: Ensure that you have added a security group to your RDS configuration to allow Heroku to access your RDS instance and added that security group to your instance. For CLI help doing this you can view the RDS docs on Heroku or login to your AWS console and do this:
So, to recap, if you've:
You should now be able to use RDS with your Rails 3 app on heroku. :)