<p>Today I needed to access a production database for my Rails app directly using a GUI application on my mac, so I figured out that this can be done by creating an SSH tunnel like so:</p> <div class="highlight"><pre class="highlight shell"><code>ssh <span class="nt">-Ng</span> <span class="nt">-L</span> <local-port>:<remote-host>:<remote-port> <user>@<remote-host> ssh <span class="nt">-Ng</span> <span class="nt">-L</span> 3307:100.64.26.11:3307 adam@100.64.26.11 </code></pre></div> <p>And then, in your Rails app, update the database.yml as if you were connecting to a local database, but specify the proper database name.</p> <div class="highlight"><pre class="highlight yaml"><code><span class="na">development</span><span class="pi">:</span> <span class="na">adapter</span><span class="pi">:</span> <span class="s">mysql2</span> <span class="na">database</span><span class="pi">:</span> <span class="s">myapp_production</span> <span class="na">host</span><span class="pi">:</span> <span class="s">127.0.0.1</span> <span class="na">port</span><span class="pi">:</span> <span class="m">3307</span> <span class="na">username</span><span class="pi">:</span> <span class="s">root</span> <span class="na">password</span></code></pre></div>