问题

一切都在我的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服务器.


Ruby 1.9.3p125

Rails 3.2.2

mysql2 gem 0.3.11

MySQL服务器:5.1.61

生产主机: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
 

  最佳答案

解决了这个问题。

我所要做的就是...

 $ RAILS_ENV=production bundle exec rails console
 

  相同标签的其他问题

mysqlruby-on-railsruby