Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you ran this command: <code>ssh -f user@mysql-server.com -L 3306:mysql-server.com:3306 -N</code> as described in the post you linked. </p> <p>A breakdown of the command:</p> <ol> <li><code>ssh</code>: that's pretty self-explanatory. Invokes <code>ssh</code>. </li> <li><p><code>-f</code>: (From the <code>man ssh</code> page)</p> <blockquote> <p>Requests ssh to go to background just before command execution. This is useful if ssh is going to ask for passwords or passphrases, but the user wants it in the background.</p> </blockquote> <p>Essentially, send <code>ssh</code> to background once you've entered any passwords to establish the connection; it gives the shell prompt back to you at <code>localhost</code> rather than logging you in to <code>remote-host</code>. </p></li> <li><code>user@mysql-server.com</code>: the remote server you'd like to log into. </li> <li><p><code>-L 3306:mysql-server.com:3306</code>: This is the interesting bit. <code>-L</code> (from the <code>man ssh</code> page):</p> <blockquote> <p>[bind_address:]port:host:hostport Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.</p> </blockquote> <p>So <code>-L 3306:mysql-server.com:3306</code> binds the <em>local</em> port <code>3306</code> to the <em>remote port</em> <code>3306</code> on host <code>mysql-server.com</code>. </p> <p>When you connect to <em>local</em> port <code>3306</code>, the connection is forwarded over the secure channel to <code>mysql-server.com</code>. The <em>remote host</em>, <code>mysql-server.com</code> then connects to <code>mysql-server.com</code> on port <code>3306</code>. </p></li> <li><p><code>-N</code>: don't execute a command. This is useful for "just forwarding ports" (quoting the man page). </p></li> </ol> <blockquote> <p>Does this command affect anything on the server? </p> </blockquote> <p>Yes, it establishes a connection between <em>localhost</em> and <em>mysql-server.com</em> on port <em>3306</em>. </p> <blockquote> <p>And how do I close this tunnel...</p> </blockquote> <p>If you've used <code>-f</code>, you'll notice that the <code>ssh</code> process you've opened heads into the background. The nicer method of closing it is to run <code>ps aux | grep 3306</code>, find the <code>pid</code> of the <code>ssh -f ... -L 3306:mysql-server.com:3306 -N</code>, and <code>kill &lt;pid&gt;</code>. (Or maybe <code>kill -9 &lt;pid&gt;</code>; I forget if just <code>kill</code> works). That has the beautiful benefit of <strong>not</strong> killing all your other <code>ssh</code> connections; if you've got more than one, re-establishing them can be a slight ... pain. </p> <blockquote> <p>... because now I can't use my local mysql properly.</p> </blockquote> <p>This is because you've effectively "captured" the <em>local</em> <code>mysql</code> process and forwarded any traffic that attempts to connect to it, off to the <em>remote</em> <code>mysql</code> process. A <em>much nicer</em> solution would be to <strong>not use local port 3306</strong> in the port-forward. Use something that's not used, like 33060. (Higher numbers are generally less used; it's pretty common to port-forward a combination like this: "2525->25", "8080->80", "33060->3306" or similar. Makes remembering slightly easier). </p> <p>So, if you used <code>ssh -f user@mysql-server.com -L 33060:mysql-server.com:3306 -N</code>, you'd then point your Zend connect-to-mysql function to <code>localhost</code> on port <code>33060</code>, which would connect to <code>mysql-server.com</code> on port <code>3306</code>. You can obviously still connect to <code>localhost</code> on port <code>3306</code>, so you can still use the local <code>mysql</code> server. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload