Rails Migrations and 'Can‘t connect to local MySQL


#1

After I set up my Rails app on Dreamhost, I tried to perform a data base migration on the production database using the command:

rake db:migrate

but I got the following error:

‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’

But this command line to run the MySQL interpreter works, proving that I actually can connect to the production database:

mysql -u -p -h | no space after ‘-p’

I finally solved my problem after viewing a 19 Jan 2006 entry at http://tom.wilcoxen.org/ . A slightly updated version follows:


If you’re running a recent rails app and are on a host like DreamHost where the RAILS_ENV isn’t set, you’ll need to use this to run your migrations:

rake environment RAILS_ENV=production db:migrate

Otherwise you’ll get this:

Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘

Or you’ll connect to your development database if you have one configured.