[英]Deployed rails app to Elastic beanstalk can't connect to RDS
I'm trying to deploy my app to Elastic Beanstalk by following this tutorial . 我正按照本教程尝试将我的应用程序部署到Elastic Beanstalk。
The app works if I use splite3
, but I can't connect the app to RDS. 如果使用
splite3
,则该应用程序可以splite3
,但无法将其连接到RDS。
I added group :production do gem 'mysql2' end
in Gemfile, and this code to config/database.yml
. 我在Gemfile中添加了
group :production do gem 'mysql2' end
gem'mysql2 group :production do gem 'mysql2' end
,并将此代码添加到config/database.yml
。
production:
adapter: mysql2
encoding: utf8
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
I added RDS in Elastic Beanstalk console . 我在Elastic Beanstalk控制台中添加了RDS。
But production.log
shows error, that indicates DB connection fails. 但是
production.log
显示错误,表明数据库连接失败。
-------------------------------------
/var/app/support/logs/production.log
-------------------------------------
I, [2014-02-09T16:01:56.520967 #29379] INFO -- : Started GET "/" for xxx.xxx.xxx.xxx at 2014-02-09 16:01:56 +0000
I, [2014-02-09T16:01:56.620738 #29379] INFO -- : Processing by PostsController#index as HTML
E, [2014-02-09T16:01:56.629835 #29379] ERROR -- : Mysql2::Error: Table 'ebdb.posts' doesn't exist: SELECT `posts`.* FROM `posts`
I, [2014-02-09T16:01:56.630802 #29379] INFO -- : Rendered posts/index.html.erb within layouts/application (4.3ms)
I, [2014-02-09T16:01:56.631068 #29379] INFO -- : Completed 500 Internal Server Error in 10ms
F, [2014-02-09T16:01:56.633962 #29379] FATAL -- :
ActionView::Template::Error (Mysql2::Error: Table 'ebdb.posts' doesn't exist: SELECT `posts`.* FROM `posts`):
eb status
shows like this. eb status
显示如下。
URL : myAppURL
Status : Ready
Health : Green
RDS Database: AWSEBRDSDatabase | myDatabaseURL:port
Probably I miss something very basic. 可能我错过了一些非常基本的东西。 What should I do to fix this problem?
我应该怎么做才能解决这个问题?
If your database is not named ebdb
you could hardcode your database name in the YAML file: 如果您的数据库未命名为
ebdb
,则可以在YAML文件中对数据库名称进行硬编码:
production:
adapter: mysql2
encoding: utf8
database: my_database_name
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.