[英]Rails: Production Rails console won't start
Everything works fine on my OS X development laptop.在我的 OS X 开发笔记本电脑上一切正常。
Deploy the app to production and it runs and displays data as expected.将应用程序部署到生产环境,它会按预期运行并显示数据。
However, when I try to run the Rails console on the production server I get an error...但是,当我尝试在生产服务器上运行 Rails控制台时,出现错误...
$ rails console -e production
/opt/deployed_rails_apps/con_app_rails_3/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:
in `connect': Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2) (Mysql2::Error)
from /opt/deployed_rails_apps/con_app_rails_3/shared/bundle/ruby/1.9.1/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'
from /opt/deployed_rails_apps/con_app_rails_3/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
I tried removing socket: /tmp/mysql.sock
from database.yml -- same result.我尝试从 database.yml 中删除
socket: /tmp/mysql.sock
- 结果相同。
Although the app runs, I do need to be able to access the console in production as well to perform certain tasks.尽管该应用程序可以运行,但我确实需要能够访问生产中的控制台来执行某些任务。
I am able to connect to the MySQL server using the MySQL command line client.我能够使用 MySQL 命令行客户端连接到 MySQL 服务器。
ruby 1.9.3p125红宝石 1.9.3p125
Rails 3.2.2导轨 3.2.2
mysql2 gem 0.3.11 mysql2 宝石 0.3.11
MySQL server: 5.1.61 MySQL 服务器:5.1.61
Production host: Linux 2.6.32-220.4.2.el6.x86_64生产主机:Linux 2.6.32-220.4.2.el6.x86_64
database.yml数据库.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: con_app_rails_3_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: con_app_rails_3_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
host: dbhost
database: con_app_rails_3_production
pool: 5
username: xxxx
password: xxxx
socket: /tmp/mysql.sock
Solved it.解决了。
All I needed to do was...我需要做的就是...
$ RAILS_ENV=production bundle exec rails console
另一种方法来做到这一点:
./script/rails console production
You can also solve this by appending the --environment=production
argument to the rails c
or rails console
command您还可以通过将
--environment=production
参数附加到rails c
或rails console
命令来解决此问题
rails c --environment=production
That's all.就这样。
I hope this helps我希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.