Rails:生产Rails控制台无法启动 [英] Rails: Production Rails console won't start
问题描述
在我的OS X开发笔记本电脑上一切正常.
Everything works fine on my OS X development laptop.
将应用程序部署到生产环境中,它将按预期运行并显示数据.
Deploy the app to production and it runs and displays data as expected.
但是,当我尝试在生产服务器上运行Rails 控制台时,出现错误...
However, when I try to run the Rails console on the production server I get an error...
$ 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'
我尝试从database.yml中删除socket: /tmp/mysql.sock
-相同的结果.
I tried removing socket: /tmp/mysql.sock
from database.yml -- same result.
尽管该应用程序可以运行,但我确实需要能够访问生产环境中的控制台以执行某些任务.
Although the app runs, I do need to be able to access the console in production as well to perform certain tasks.
我能够使用MySQL命令行客户端连接到MySQL服务器.
I am able to connect to the MySQL server using the MySQL command line client.
红宝石1.9.3p125
ruby 1.9.3p125
Rails 3.2.2
Rails 3.2.2
mysql2 gem 0.3.11
mysql2 gem 0.3.11
MySQL服务器:5.1.61
MySQL server: 5.1.61
生产主机:Linux 2.6.32-220.4.2.el6.x86_64
Production host: Linux 2.6.32-220.4.2.el6.x86_64
database.yml
database.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
推荐答案
已解决.
我要做的就是...
$ RAILS_ENV=production bundle exec rails console
这篇关于Rails:生产Rails控制台无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!