【问题标题】:Rails connects to MySQL from WEBrick but not from PassengerRails 从 WEBrick 连接到 MySQL,但不是从 Passenger
【发布时间】:2023-03-18 03:25:01
【问题描述】:

我刚刚使用 MySql 创建了一个新的 Rails 4 应用程序,如下所示:

rails new mysqltest -d mysql

并使用正确的凭据修改了 database.yml。

我生成了一个示例控制器并更新了根路由的路由。

当我开始在生产中使用 WEBrick 时,

rails s -e production

该网站有效。我看到了索引页。

当我开始使用没有 3000 端口的乘客时,我看到以下错误:

database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)

Passenger 正在生产环境中运行。

我的数据库.yml

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem 'mysql2'
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql2
  encoding: utf8
  database: sample
  pool: 5
  username: sample
  password: sample
  socket: /var/run/mysqld/mysqld.sock

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql2
  encoding: utf8
  database: sample
  pool: 5
  username: sample
  password: sample
  socket: /var/run/mysqld/mysqld.sock

production:
  adapter: mysql2
  encoding: utf8
  database: sample
  pool: 5
  username: sample
  password: sample
  socket: /var/run/mysqld/mysqld.sock

【问题讨论】:

  • 您似乎还没有为生产环境配置数据库。你能分享你的 database.yaml 吗?

标签: mysql ruby-on-rails passenger


【解决方案1】:

我在 database.yml 文件和 apache 配置文件中使用的情况不同。

两者应该相同。例如。 production.

在 apache 配置中,我给出了 Production。将其更改为production 后,它起作用了。

来源 - https://groups.google.com/forum/#!topic/phusion-passenger/Kr-R0gSw6i8

【讨论】:

  • 救了我,但也检查了生产配置的编码。我忘了一个 f :P
【解决方案2】:

您是否创建了本地生产数据库?

rake db:create:all
RAILS_ENV=production bundle exec rake db:migrate

您的 database.yml 文件设置是否正确以使用生产数据库?

您的 gem 文件中是否有 mysql gem。

常见问题。

【讨论】:

  • rake 任务不是必需的,因为我手动创建了数据库。 database.yml 设置正确(因为它在 WEBrick 中工作)。我的 Gemfile 中有 mysql2。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-25
  • 2017-02-27
  • 1970-01-01
  • 1970-01-01
  • 2015-10-28
  • 1970-01-01
  • 2013-04-21
相关资源
最近更新 更多