title: MySQL connection over SSH tunnel
body: <p>I have set up a SSH tunnel between two servers <strong>A</strong> and <strong>B</strong>. <strong>B</strong> has MySQL server, and this works:</p>
  
  <pre><code>mysql -h localhost -P 3306 -u user -p
  </code></pre>
  
  <p>While this doesn't:</p>
  
  <pre><code>mysql -h 127.0.0.1 -P 3306 -u user -p
  </code></pre>
  
  <p>Although my.cnf has these lines:</p>
  
  <pre><code>bind-address        = 127.0.0.1
  # Next addr differs slightly, but anyway
  bind-address        = 99.99.99.99
  </code></pre>
  
  <p>Now about the tunnel. It connects the following:<code>(A) localhost(9989) -&gt; (B) localhost(3306)</code>
  But when (on <strong>A</strong>,  with ports forwarded) I do </p>
  
  <pre><code>mysql -v -h 127.0.0.1 -P 9989 -u user userdb -p
  </code></pre>
  
  <p>I get <code>ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0</code></p>
  
  <p>And when I do</p>
  
  <pre><code>mysql -v -h localhost -P 9989 -u user userdb -p
  </code></pre>
  
  <p>I get <code>ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)</code></p>
  
  <p>What might be the reason? What am I doing wrong?</p>