Kids, don't try this at work

A user is experiencing a nasty bug in your webapp in production that you can’t reproduce locally, and you need to fix it super fast. What do you do?

Start the SSH tunnel to your production database

ssh -f -L 3307: -N

3306 is the port MySQL usually runs on. 3307 is the local port we’re opening for the tunnel. We’ll use SSH tunnel so that we don’t have to deal with firewall poking or mysql granting.

Configure app's database connection

Basically you just need to change connection settings to use port:3307 and host: and the login/password of course.

Have some haxor backdoor

This will allow you to login as a user without user password. It’s best to make this code work only in development environment in case of the accidental commit - ring any bells? Here’s one example in Rails. Adjust it to work with your system and your use case.

Handle subdomains if any

If your app is using subdomains you should already be using or which saves you the trouble of messing around with /etc/hosts

Be fucking careful!

Your local code will now work with production data and you’ll be able to login as a user which means you should really be careful about what you do with data.

Published 2011-07-09 · Home