有人可以阐述为什么应用程序在生产与开发模式下表现不同。我已检查并重新检查config/database.yml
并确保用户名和密码正确。事实上,在写这篇文章的时候,我已经设定了开发和生产数据库都是一样的。然而,当我在生产环境中运行服务器时,Mysql2抱怨访问被拒绝,但在开发环境中工作正常。Rails应用程序在开发与生产中的表现有所不同
运行时发生同样的事rails c production
vs rails c development
,开发中没有错误,但在生产中没有发生Mysql2访问错误。
生产模式
$ rails s -e production
=> Booting WEBrick
=> Rails 4.0.2 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-03-19 18:20:22] INFO WEBrick 1.3.1
[2014-03-19 18:20:22] INFO ruby 2.1.0 (2013-12-25) [x86_64-freebsd10.0]
[2014-03-19 18:20:22] INFO WEBrick::HTTPServer#start: pid=10800 port=3000
I, [2014-03-19T18:20:30.569167 #10800] INFO -- : Started GET "/" for 192.168.1.102 at 2014-03-19 18:20:30 +0200
F, [2014-03-19T18:20:30.709229 #10800] FATAL -- :
Mysql2::Error (Access denied for user 'root'@'localhost' (using password: YES)):
发展模式
$ rails s -e development
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-03-19 18:22:53] INFO WEBrick 1.3.1
[2014-03-19 18:22:53] INFO ruby 2.1.0 (2013-12-25) [x86_64-freebsd10.0]
[2014-03-19 18:22:53] INFO WEBrick::HTTPServer#start: pid=10898 port=3000
Started GET "/" for 192.168.1.102 at 2014-03-19 18:23:03 +0200
Processing by Rails::WelcomeController#index as HTML
Rendered /home/user/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/templates/rails/welcome/index.html.erb (2.3ms)
Completed 200 OK in 24ms (Views: 11.6ms | ActiveRecord: 0.0ms)
这里是我的config/database.yml的。
development:
adapter: mysql2
encoding: utf8
database: amo
pool: 5
username: root
password: mypass
host: localhost
production:
adapter: mysql2
encoding: utf8
database: amo
pool: 5
username: root
password: mypass
host: localhost
O/S:10.0 FreeBSD的64位
红宝石:2.1.0(安装在使用Rbenv)
滑轨:4.0.2
显示你的'config/database.yml'。 –
当然。正在编辑我的帖子以添加它并看到您的评论。完成:) –
你有没有解决你的问题? –