Rails database.yml configuration with different sockets on dev, test and production

Go To StackoverFlow.com

0

So I am developing locally using Rails 3.2 and mysql. My local machine is a Mac and my database.yml for development is:

development:
    adapter: mysql2
    database: dbname
    encoding: utf8
    host: localhost 
    port: 3306
    timeout: 5000
    socket: /tmp/mysql.sock

And for test it's

test:
    adapter: mysql2
    database: dbname
    encoding: utf8
    host: localhost 
    port: 3306
    timeout: 5000
    socket: /var/lib/mysql/mysql.sock

Test and production servers are on CentOS and the socket works correctly when deploying to them. However I just went to do a manual rake and got the

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

My site works, but I'm curious if I'm should be handling database.yml separately for deployment since it's somehow looking at development when I run rake?

Looked for a suggestion and didn't see the same issue, apologize in advance if I missed it.

2012-04-04 00:07
by creativereason


2

You can specify the Rails environment when you run the Rake task.

rake db:migrate RAILS_ENV=production
2012-04-04 00:30
by Bob.
Thanks Bob. I tried that and it worked for the rake for sure - creativereason 2012-04-04 17:52
Excellent! Since you're new to Stack Overflow, I'll point out that you can feel free to accept this as the answer to your question in order to help out with your and my reputations. Best regards - Bob. 2012-04-05 17:50


0

I can think of three alternatives:

  • Change your database.yml and just don't version in the changes
  • Use capistrano and its shared folder to handle different database.yml
  • Use an environment variable i.e. ENV['TEST_SOCKET']
2012-04-04 00:22
by Pedro Nascimento
Thanks for the answer Pedro. Environment variable sounds like it could work. Is that something you can tie into a capistrano deployment - creativereason 2012-04-04 15:46
You can put in your and your test server's .profile, .bashrc, .zshrc or whatever you use for your shell - Pedro Nascimento 2012-04-04 17:07
Ads