Connecting to Production Database

I would like to connect to my production database from my local
machine, so that I can import/export data using rake commands. (for
example: RAILS_ENV=production rake db:fixtures:load)

My database.yml file is typical:

development:
adapter: mysql
database: my_app_development
username: root
password:
host: localhost

test: …

production:
adapter: mysql
database: my_app_production
username: root
password:
host: localhost

The production database works for the rails app itself, presumably
because the app and the db run on the same machine, and hence the
‘localhost’ to the app is indeed the db server, but I cannot access
the db from local rake tasks. I’ve tried setting the production host
to the ip of the server, but that didn’t work either.

Any thoughts on how to establish this remote production db connection
would be greatly appreciated.

Your discription is not 100% clear, but I am assuming your application
and MySQL server is on the Internet somewhere, you have a copy of your
application on your local PC, and you want to be able to run commands
like rake on your local PC and have them execute on the remote server.

If this is the case I would suggest you look into a tool like
Capistrano because it will do these things much more safely and
securely. If you’re intent on doing it by hand then you need to look
into the MySQL command ‘GRANT’ in order to give permission for your
local PC to execute SQL statements on the server. Note that if you
have a DCHP address from your ISP that changes on any kind of regular
basis you will either have to change the permissions on the SQL server
whenever your IP changes, or make the permissions vague enough to
allow undesirables to access your DB. This is one of the key reasons
Capistrano is so awesome.

Short answer: google ‘MySQL GRANT’ and/or ‘capistrano’.

—A