# Connecting to Production Database

**URL:** <https://www.ruby-forum.com/t/connecting-to-production-database/106581>\
**Category:** Rails\
**Created:** [June 12, 2007, 5:50am UTC](https://www.ruby-forum.com/t/connecting-to-production-database/106581 "2007-06-12T05:50:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 12, 2007, 5:50am UTC](https://www.ruby-forum.com/t/connecting-to-production-database/106581/1 "2007-06-12T05:50:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 12, 2007, 5:53pm UTC](https://www.ruby-forum.com/t/connecting-to-production-database/106581/2 "2007-06-12T17:53:05Z")

</div>

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
