8

Everything works fine on my OS X development laptop.

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 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.

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.


ruby 1.9.3p125

Rails 3.2.2

mysql2 gem 0.3.11

MySQL server: 5.1.61

Production host: 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

4 Answers 4

36

Solved it.

All I needed to do was...

$ RAILS_ENV=production bundle exec rails console
1
  • I didn't need to do bundle exec, but specifying RAILS_ENV=production FIRST on the command line was important. May 19, 2013 at 20:44
8

Another way to do this:

./script/rails console production

1

I solved with run:

 RAILS_ENV=production bundle exec rails c

more details on link

0

You can also solve this by appending the --environment=production argument to the rails c or rails console command

rails c --environment=production

That's all.

I hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.