Rails 和 Amazon RDS:“未配置生产数据库”

Posted

技术标签:

【中文标题】Rails 和 Amazon RDS:“未配置生产数据库”【英文标题】:Rails & Amazon RDS: "production database is not configured" 【发布时间】:2012-11-26 12:45:27 【问题描述】:

我对 AWS 的所有事物都是全新的,并试图在 Beanstalk 上启动我的 Rails 应用程序。我正在关注recent tutorial,但我无法将我的应用程序连接到 RDS。乘客屏幕出现错误:

production database is not configured (ActiveRecord::AdapterNotSpecified)

我的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'] %>

我确实配置并运行了一个 RDS 实例。我还 ssh'ed 到 EC2 实例,并验证我可以通过 RDS_USERNAME、RDS_HOSTNAME 等成功连接到 RDS。

想也许我需要在 MySQL 中手动创建我的数据库,我使用 MySQL 客户端来执行此操作,但我仍然遇到同样的错误。

所以我再次在 EC2 实例上手动检查了我的项目并运行 bundle exec rake db:migrate --trace 以更全面地了解它的失败之处:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
rake aborted!
production database is not configured
/usr/share/ruby/1.9/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
/usr/share/ruby/1.9/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
/usr/share/ruby/1.9/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:129:in `establish_connection'
/usr/share/ruby/1.9/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
/usr/share/ruby/1.9/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
/usr/share/ruby/1.9/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
/usr/share/ruby/1.9/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/usr/share/ruby/1.9/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `each'
/usr/share/ruby/1.9/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/usr/share/ruby/1.9/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/base.rb:721:in `<top (required)>'
/usr/share/ruby/1.9/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:6:in `block (2 levels) in <top (required)>'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:227:in `call'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:227:in `block in execute'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:222:in `each'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:222:in `execute'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/usr/share/ruby/1.9/monitor.rb:211:in `mon_synchronize'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:159:in `invoke_with_call_chain'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:185:in `each'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:185:in `invoke_prerequisites'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/usr/share/ruby/1.9/monitor.rb:211:in `mon_synchronize'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:159:in `invoke_with_call_chain'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/task.rb:152:in `invoke'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:141:in `invoke_task'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `block (2 levels) in top_level'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `each'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:99:in `block in top_level'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:108:in `run_with_threads'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:93:in `top_level'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:71:in `block in run'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:158:in `standard_exception_handling'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/lib/rake/application.rb:68:in `run'
/usr/share/ruby/1.9/gems/1.9.1/gems/rake-10.0.2/bin/rake:37:in `<top (required)>'
/usr/bin/rake:23:in `load'
/usr/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate => db:load_config

【问题讨论】:

【参考方案1】:

是用户错误:从链接文章中复制/粘贴导致“空格”显然是一些 unicode 杂乱无章而不是 ASCII 32。

经验教训:使用od -c your_file.yml 来诊断潜在的有趣字符。

【讨论】:

非常感谢您的建议!

以上是关于Rails 和 Amazon RDS:“未配置生产数据库”的主要内容,如果未能解决你的问题,请参考以下文章

设置 Amazon EC2 和 Amazon RDS

Amazon RDS 和 Elastic Beanstalk 连接

使用 Elastic Beanstalk 和 Amazon RDS 的连接池

Amazon RDS 和 VPC 终端节点连接

Amazon AWS RDS MySQL - 实例和定价

Amazon RDS(关系数据存储)和 SSIS