2012-05-03 100 views
8

一切工作正常我的OS X開發筆記本電腦。生產軌道控制檯將無法啓動

將應用程序部署到生產,並按預期運行並顯示數據。

然而,當我嘗試運行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' 

我試圖去除的database.yml socket: /tmp/mysql.sock - 同樣的結果。

雖然應用程序運行,但我確實需要能夠訪問生產中的控制檯以執行某些任務。

我能夠使用MySQL命令行客戶端連接到MySQL服務器。


紅寶石1.9.3p125

的Rails 3.2.2

mysql2寶石0.3.11

MySQL服務器:61年5月1日

生產主持人:Linux的2.6.32- 220.4.2.el6.x86_64

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 

回答

35

解決了它。

所有我需要做的是...

$ RAILS_ENV=production bundle exec rails console 
+0

我不需要執行'bundle exec',但是在命令行上指定'RAILS_ENV = production' FIRST很重要。 –

8

另一種方式來做到這一點:

./script/rails console production

1

我跑解決:在

RAILS_ENV=production bundle exec rails c 

更多細節link