Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Production Rails console won't start

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
like image 411
Ethan Avatar asked May 03 '12 23:05

Ethan


2 Answers

Solved it.

All I needed to do was...

$ RAILS_ENV=production bundle exec rails console
like image 60
Ethan Avatar answered Oct 02 '22 18:10

Ethan


Another way to do this:

./script/rails console production

like image 36
nyaa Avatar answered Oct 02 '22 18:10

nyaa